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
  • 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

Children