Share

Script Invocation Behavior and Constraints

Learn about script invocation behavior in Fusion Manage and the constraints applied by the scripting engine.

Script Invocation Trees and Branches

When a script creates, modifies, or performs a transition on workspace items, it may trigger behaviour scripts (create, modify) or transition scripts (transition) just as if a user had created, modified, or transitioned the item. These scripts may, in turn, create, modify, or perform transitions on further workspace items, potentially triggering even more scripts. This series of scripts triggering other scripts is called a script invocation tree.

Example script invocation tree

If ScriptA creates two items in Workspace B, which has an onCreate script (OnCreateB) that edits two items in Workspace C, which in turn has an onModify script (OnModifyC) that updates the items edited by onCreateB, the script invocation tree looks like this:

ScriptA(item A1) // Script creates two items in workspace B
|
+- OnCreateB(item B1) // Script modifies two items in workspace C
|   |
|   +- OnModifyC(item C1) // Script updates item C1
|   |
|   +- OnModifyC(item C2) // Script updates item C2
|
+- OnCreateB(item B2) // Script modifies two items in workspace C
    |
    +- OnModifyC(item C3) // Script updates item C3
    |
    +- OnModifyC(item C4) // Script updates item C4

In this example, when ScriptA runs on item A1 - written as ScriptA(A1) - it creates two items in workspace B: item B1 and item B2. Creating item B1 triggers the script OnCreateB(B1), which modifies two items in workspace C: item C1 and item C2. At the same time, creating item B2 triggers script OnCreateB(B2), which modifies two more items in workspace C: item C3 and item C4. Modifying the four items in workspace C triggers script OnModifyC for each of the items (OnModifyC(C1), OnModifyC(C2), etc).

A script invocation branch is one path through the tree. For example, the script invocation OnModify(C3) is on the branch which goes ScriptA(A1)->OnCreateB(B2)->OnModifyC(C3).

Script Invocation Rules

To prevent loops in script triggering chains, the Fusion Manage Scripting Engine enforces the following rules:

  1. An OnEdit script may not be run on an item that was created earlier in the script invocation branch.
  2. A script cannot be called more than once on any given item in a script invocation branch.
  3. A creation script cannot be called more than once in a script invocation branch.

If a script that violates any of these rules is triggered, it is ignored. The rest of the script chain proceeds as usual.

Rule violation examples

The following script invocation trees illustrate scenarios that violate these rules.

Rule 1

OnCreateX(X1) // Script creates item in workspace Y
|
+- OnCreateY(Y1) // Script modifies X1
     |
     +- OnModifyX(X1) // Script normally called when X1 is modified

The call to OnModifyX(X1) here is not allowed because the creation script OnCreateX(X1) was called earlier. In this case, OnCreateX(X1) and OnCreateY(Y1) run normally, but OnModifyX(X1) is skipped. Note that the modifications to X1 in script OnCreateY(Y1) are saved but do NOT trigger OnModifyX(X1).

Rule 2

OnCreateX(X1) // Script modifies an item in workspace Y
|
+- OnModifyY(Y1) // Script modifies Z1
     |
     +- OnModifyZ(Z1) // Script modifies Y1
        |
         +- OnModifyY(Y1) // Same as two steps earlier in branch

The second call to OnModifyY(Y1) here is not allowed because the same script has already been called on the same item earlier in the branch. In this case, OnCreateX(X1), OnModifyY(Y1), and OnModifyZ(Z1) run normally, but the second OnModifyY(Y1) is skipped. Note that the modifications to Z1 are saved but do NOT trigger OnModifyY(Y1).

Rule 3

OnCreateX(X1) // Script modifies an item in workspace Y
|
+- OnModifyY(Y1) // Script creates another item in workspace X
     |
     +- OnCreateX(X2) // Multiple creations in same workspace

The call to OnCreateX(X2) here is not allowed because an item has already been created in workspace X in this branch. In this case, OnCreateX(X1) and OnModifyY(Y1) run normally, but the OnCreateX(X2) is skipped. Note that item X2 is created but does NOT trigger OnCreateX(X2).

Note As you can see from the original ScriptA example above, you can have multiple calls to the same OnCreate script in a single script invocation tree - just not in the same script invocation branch. The same is the case in the other rules: these restrictions apply only within the context of a branch, not across all branches of the tree.

Was this information helpful?