Creating a Script Custom Activity

You can create an activity based on a user-defined script. The following procedure creates an activity that changes a decimal value to a percentage value, for example, 0.7 is converted to 70%.

Procedure

  1. From your Workflow window in the Activities pane, click Create Activitycreate_activity_script_01.

  2. In the New Activity Type dialog box, from the Activity Type list, select Script, and then click OK.

  3. In the New Script Activity dialog box, click the General tab and provide the following general details:

    • For the Name property, enter the name of the activity, for example, PercentageToValue. This is the name you see in the Activities pane.

    • For the Description property, specify what the activity does.

    • For the Group property, select the activity group where you want to place the new activity, for example, Utilities. If you do not select a group, the new activity is placed in the Ungrouped group.

  4. Click the Inputs tab to define the input variables for the activity.

    In our example, the PercentageToValue activity needs a variable to store the percentage value:

    1. Click Add.

    2. In the Add new property dialog box, enter the name of the variable in the Variable Name box, for example, percentageValue.

    3. Select float from the Variable Type list, and then click OK.

    You can specify default values for the new input in the Value column.

  5. Click the Script tab to specify the Java or JavaScript code which this activity will perform.

    Following our example, the PercentageToValue activity will need code to return the percentage from the given float value, as shown below:

    return (activity.getInput("percentageValue")*100) + "%";

    Also, specify the activity output in the Output Variable box and select the output type from the Output Type list.

    create_activity_script_05

  6. Click OK.

    The new activity is listed in the Activities pane under a specific activity group. You can drag the activity to the design area to start using it in your Workflow.

Loading...