Call script from custom class - v8.0.1

Hello Experts

I have a custom class, and in the new operator I am calling an existing script to do some calculations. However, when I compile I get the following error:

Reference to a non-shared member requires an object reference

I guess this make sense since all the customer scripts reside in a separate class.

Question is: How can I access the functions (i.e. scripts) from within my custom class?

Thanks

Kin

Parents Reply Children
  • FYI - This question has already been asked it seems, shame there is no solution though. I did try calling the script by creating an object of DynScripts.Scripts but that did not work, when runing through designer I get an object reference not set error when calling CCC_MyFunc even though the code compiles (locally)

    https://www.oneidentity.com/community/identity-manager/f/forum/29982/script-library---customer-scripts---public-class-ccc_mynewclass-is-outside-the-namespace/73364#73364

  • You should be able to use the ScriptRunner - class to call the script.

    Attached are two sample functions to demonstrate the usage. The first function CCC_ExecuteScript is in my case a script that is stored in OneIM itself as well, just to demonstrate the usage of the ScriptRunner class. In your case, you need to have access to the current Session somehow.

    The second function CCC_MyFancyFunction is the script that should be called.

    Please be aware, that when you test this in the SystemDebugger, it will only work if the called script is already stored and compiled in the OneIM database.

    Public Function CCC_ExecuteScript(ByVal ScriptName As String, ByVal name As String, ByVal email As String) As String
    
        Dim runner = New VI.DB.Scripting.ScriptRunner(Session.Scripts()(VI.DB.Scripting.ScriptContext.Scripts), Session)
        If runner.Class.HasMethod(ScriptName, {GetType(String), GetType(String)}) Then
            Dim result = runner.Eval(ScriptName, {name, email})
            Return CStr(result)
        End If
        Return String.Empty
    End Function
    
    Public Function CCC_MyFancyFunction(ByVal name As String, ByVal email As String) As String
    
        Return String.Format("{0} ({1})", name, email)
    End Function

  • Actually I just copied your example (CCC_ExecuteScript) into my class as a new class function, and got the same error (reference to a non-shared member requires an object reference)

  • Right, so the issue is I somehow need to get Session passed into the function (as you mentioned previously Markus, I missed that part). I'll work on this and if I find a solution I'll update this - I'm guessing I need to pass the session as a parameter from the object of the class somehow. Keeping this thread open in the meantime

  • Got it, pasting the source code here - the key is to have a session member variable

    Class Test
    
    	Public _s As VI.DB.Entities.ISession
    	Dim _prop As String
    	
    	Public Property Prop() As String
    		Get
    			Return Me._prop
    		
    		End Get
    		
    		Set(ByVal t As String)
    			Dim runner = New VI.DB.Scripting.ScriptRunner(Me._s.Scripts()(VI.DB.Scripting.ScriptContext.Scripts), Me._s)
    			Dim result = runner.Eval("CCC_MyScript", {"John", "@company.com"})
    			Me._prop = CStr(result)
    		End Set
    		
    	End Property
    	
    End Class
    
    Public Function  CCC_Myfunc() As String
    
    		Dim p As New Test With {._s = Session, .Prop = "ha"}
    		Return p.Prop
    	
    End Function