Loading...

Defining Activity Inputs Using Expressions

Table of Contents

Expressions are input values which typically consist of a variable and/or a hard-coded value (integer or non-integer). The variable can be an activity output, a workflow input or a workflow variable. Hard-coded values can also be Java objects.

Some activities may require expressions as their input values. Decision and Switch are some of the activities that use this type of input.

The following sections describe the steps to define activity inputs using expressions.

Specifying a Variable and a Hard-Coded Value

Consider the following example where the output of an activity is used as a variable to specify the input value of another activity:

You have a Workflow to check if specific clients in the CommCell are reachable. As part of the Workflow, you have a Decision activity which analyzes the results of the CheckReady activity and checks the client connectivity. To appropriately configure the Decision activity, you must specify the expression required by this activity, which will be based on the exit code output of the CheckReady activity:

  1. From the workflow design area, right-click the Decision activity and then click Properties.
  2. Click the Inputs tab and then click in the Value box.
  3. For the expression value, click Insert Variable, expand the CheckReady activity, and select exitCode. When added, it may look like this in the Value column:

    xpath:{/workflow/CheckReady_2/exitCode}

  4. To make the expression represent the successful scenario of the CheckReady activity, exitCode must equal 0. Therefore, you must type == 0 next to the exit code variable in the Value column:

    xpath:{/workflow/CheckReady_2/exitCode} == 0

Specifying Java or JavaScript Code

In addition to assigning variables and values for an activity input, you can write code in Java or JavaScript to obtain the value for the activity input. You can also write code to to perform validation checks on the activity input.

Code can be entered into all activities when surrounded by the following tags:

  • Java: opening java:{ and closing }:java tags
  • JavaScript: opening js:{ and closing }:js tags

Some activities do not require the tags. Java and JavaScript can be entered into the following activities without using the tags:

  • Script Activity
  • Transition Conditions
  • OnEnter/OnComplete Scripts
  • Decision

Procedure

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

    The activity dialog box appears.

  2. On the Inputs tab, from the Value column of the activity input, click <Edit...>.

  3. Specify the Java or JavaScript code in the input dialog box and click OK.

Examples

Java Example

An activity takes a library entity object as an input, and the ID of the library is stored in a workflow variable. You can obtain the library entity value for the activity by using Java code. The following code gets the library entity for the activity using the workflow variable where the library ID is stored:

#Java Code Sample

java:{
commvault.msgs.CvEntities.LibraryEntity libraryEntity = new commvault.msgs.CvEntities.LibraryEntity();
libraryEntity.setLibraryId(xpath:{/workflow/variables/libraryId});
activity.library = libraryEntity;
}:java

JavaScript Example

The GET Client Properties REST API was accessed using the HttpClient activity. If you want to retrieve the client name from the JSON response, type the following script:

var response = JSON.parse(xpath:{/workflow/HttpClient_3/output});
var clName = response.clientProperties[0].client.clientEntity.clientName;