Loading...

Adding an OnComplete Script

You can execute Java or JavaScript at the end of an activity, to verify the input. You can use this script to change the output, fail the activity if there is a problem in the output, and update a global variable depending on what the outputs of an activity are.

Example: Verify the Output

In the Execute activity, there is XML to associate a CommCell user with a user group. Both the user and user group values are provided during execution. The following script verifies whether the XML is executed without error codes (that is, the exit code is not 0). If an error code is present, the script fails the workflow.

  1. From the workflow design area, right-click the activity, and then click Properties.

    The activity dialog box appears.

  2. On the OnComplete Script tab, enter the following code:

    #OnComplete Script Sample

    if (activity.exitCode == 0)
    {
    XML xml = utils.parseXml(activity.outputXml);
    activity.exitCode = Integer.parseInt(xml.selectSingleNode("/App_UpdateUserGroupPropertiesResponse/response/@errorCode"));
    if (activity.exitCode != 0) {
    workflow.setFailed(xml.selectSingleNode("/App_UpdateUserGroupPropertiesResponse/response/@errorString"));
    }
    }

    Tip: Click Insert Variable to add variables as needed.

  3. Click OK.

Example: Update the Workflow at the End of an Activity

The following script sets the workflow to 60% complete at the end of an activity.

#OnComplete Script Sample

workflow.setCompletionPercentage(60);

Last modified: 11/19/2020 2:58:54 PM