This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Pass base object of process into a script

 Is there a way to pass the base object of a process into a script. For example, with a base object of Department I could pass to a script $ShortName$ and that would give me the shortname in the script but I address quite a few variables on the department object so I would like to pass in the department and then look at the attributes from within the script so there aren't alot of parameters to pass in. I could pass the UID and then do a look up in the database but I think this would be expensive and this script would be called many times plus the department has already been loaded by the process. Is there a way to pass the base object of a process into a script parameter? If so, what's the object type that the function would need to receive as a parameter?

Parents
  • The Entity and the Base object are only available during the generation of the process chain, when these objects are living live in the object layer.

    When you execute a script in the script component, you do not have such an object live in your object layer during the start if the script. That's why you need to pass a serialized representation to the script via the script component. Remember that the execution of the script in the script component istotally decoupled and asynchronous to your object modification that generated the process chain.

    As you are using version 7 you could use an entity patch instead of the SingleDBObjectSnapshot which is the current and future proof way to serialize an Entity.

    ' Create your EntityPatch as XML
    ' Option 1: Using the build in script DPR_GetFullEntityPatch
    Value = DPR_GetFullEntityPatch(Entity)
    ' Option 2: Using the following code
    Value = EntityPatch.Create(sourceEntity, Session.MetaData(), DiffMode.AllContent).ToXml()
    

    To revive the Entity in your script you can use the following code as in the sample.

    Public Function SDK_CreateEntityFromPatch(ByVal sourceEntityPatch As StringAs IEntity
     
        ' Create an Entity from the patch
        Dim myPatch As EntityPatch = New EntityPatch(sourceEntityPatch)
        Return myPatch.AsEntity(Session.MetaData(), EntityFromPatchBehavior.Default, Session.Source())
    End Function

    HTH

Reply
  • The Entity and the Base object are only available during the generation of the process chain, when these objects are living live in the object layer.

    When you execute a script in the script component, you do not have such an object live in your object layer during the start if the script. That's why you need to pass a serialized representation to the script via the script component. Remember that the execution of the script in the script component istotally decoupled and asynchronous to your object modification that generated the process chain.

    As you are using version 7 you could use an entity patch instead of the SingleDBObjectSnapshot which is the current and future proof way to serialize an Entity.

    ' Create your EntityPatch as XML
    ' Option 1: Using the build in script DPR_GetFullEntityPatch
    Value = DPR_GetFullEntityPatch(Entity)
    ' Option 2: Using the following code
    Value = EntityPatch.Create(sourceEntity, Session.MetaData(), DiffMode.AllContent).ToXml()
    

    To revive the Entity in your script you can use the following code as in the sample.

    Public Function SDK_CreateEntityFromPatch(ByVal sourceEntityPatch As StringAs IEntity
     
        ' Create an Entity from the patch
        Dim myPatch As EntityPatch = New EntityPatch(sourceEntityPatch)
        Return myPatch.AsEntity(Session.MetaData(), EntityFromPatchBehavior.Default, Session.Source())
    End Function

    HTH

Children
No Data