Adding an OnComplete Script to an Activity

Updated

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

Example: Verify the Output

The Execute activity includes 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. For the activity that you want to add an OnComplete script,open the activity properties.

  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: To add variables, click Insert Variable.

Example: Update the Completion Status 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);

Opening the Workflow Activity Properties