Script Library - Customer Scripts - Public Class CCC_MyNewClass is outside the Namespace

Greetings!

I defined a new class in a Customer Scripts, but it has been created outside the DynScripts Namespace. The problem is obviously that I cannot create an instance of this Object in other Customer Scripts and either use any Sub/Function from them.

Example

CCC_Script 1:

Public Class CCC_MyNewClass

Public Firstname As String

Public Lastname As String

Public Sub Save()

'Save object

End Sub

End Class

CCC_Script2:

Public Sub CCC_MyCustomSub ()

Dim MyNewClass AS ?Namespace?.CCC_MyNewClass

End Sub

How do you recommend the implementation and usage of Classes in One Identity Scripts/Process? Any known Best Practices? Should I maybe use Inheritance from DynScripts.Scripts? Is this possible anyway?

Thank you in advance

Parents
  • I made it work somehow but now the problem is just the opossite, the new class is not able to call a method from DynScripts.Scripts

    I tried to declare a variable cccScripts As DynScripts = New DynScripts.Scripts but in runtime it crashes as cccScripts.CCC_MyCustomSub2() is called. Am I doing something wrong?

    Exception has been thrown by the target of an invocation.
    at Designer.ScriptEditor.ScriptTestEditor.ExecuteScript(ScriptItem sItem)
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
    Object reference not set to an instance of an object.
    at DynScripts.scripts.MyCustomSub(String myString)
    at DynScripts.scripts.CCC_MyNewClassObject.Save()
    at DynScripts.scripts.CCC_MyCustomScriptSub2(String myString)
    at VI.DB.Scripting.ScriptBase.LanguageDependent(String table, String column, String key, Object[] parameters)

Reply
  • I made it work somehow but now the problem is just the opossite, the new class is not able to call a method from DynScripts.Scripts

    I tried to declare a variable cccScripts As DynScripts = New DynScripts.Scripts but in runtime it crashes as cccScripts.CCC_MyCustomSub2() is called. Am I doing something wrong?

    Exception has been thrown by the target of an invocation.
    at Designer.ScriptEditor.ScriptTestEditor.ExecuteScript(ScriptItem sItem)
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
    Object reference not set to an instance of an object.
    at DynScripts.scripts.MyCustomSub(String myString)
    at DynScripts.scripts.CCC_MyNewClassObject.Save()
    at DynScripts.scripts.CCC_MyCustomScriptSub2(String myString)
    at VI.DB.Scripting.ScriptBase.LanguageDependent(String table, String column, String key, Object[] parameters)

Children
  • Forget the "I made it work somehow" as the class can be instanced in Scripts but not in Processes.
    If someone could help I will provide more information

  • As long as you use the new class in other scripts, there shouldn't be an issue.

    The default script QER_CloudAssistant_LifeCycle uses this for example.

    ...
    		Public Class CloudAssistantCredentials
                Implements IJoinCredentials
    
                Public Sub New(ByVal _credentials As String, ByVal _tokenEndpoint As String, ByVal _apiEndpoint As String)
                    Credentials = _credentials
                    TokenEndpoint = _tokenEndpoint
                    ApiEndpoint = _apiEndpoint
                End Sub
    
                Public ReadOnly Property Credentials As String Implements IJoinCredentials.Credentials
                Public ReadOnly Property TokenEndpoint As String Implements IJoinCredentials.TokenEndpoint
                Public ReadOnly Property ApiEndpoint As String Implements IJoinCredentials.ApiEndpoint
                Public Property SenderId As Guid Implements IJoinCredentials.SenderId
            End Class
            ...        
        ...
    		Public NotInheritable Class CloudAssistantClient
    			Implements IDisposable
    
    			Public Sub New(ByVal _cloudAssistantCredentials As CloudAssistantCredentials)
                ...
                End Sub
    
    			Public Sub New(ByVal credentials As String, ByVal tokenEndpoint As String, ByVal apiEndpoint As String)
    				Dim _cloudAssistantCredentials = New CloudAssistantCredentials(credentials, tokenEndpoint, apiEndpoint)
                ...
                End Sub
    
    			Public ReadOnly Property Client As CloudAssistantApi
    
    			Private Sub Dispose() Implements IDisposable.Dispose
    				DirectCast(Client, IDisposable).Dispose()
    			End Sub
    		End Class
            
            ...
            Public Function QER_CloudAssistant_BuildCredentials() As CloudAssistantCredentials
                ...
                Return New CloudAssistantCredentials(credentials, tokenEndpoint, apiEndpoint)
            End Function