Script APIs for Workflows

Updated

You can use script APIs in script activities, in OnStart and OnComplete scripts, and when Java tags are used.

API

Description

Examples

workflow.getInput(final String name)

Returns the current value of the input.

workflow.getInput("clientName");

workflow.setInput(final String name, final Object obj)

Sets the input to a new value.

workflow.setInput("clientName", "Client001");

workflow.setInput("clientName", xpath:{/workflow/Script_1/output});

workflow.getVariable(final String name)

Returns the current value of the variable.

workflow.getVariable("strErrorMessage");

The following example uses getVariable and setVariable to append an item to a list:

List myList = workflow.getVariable("myList");
myList.add(newitem);
workflow.setVariable("myList", myList);
    

workflow.setVariable(final String name, final Object obj)

Sets the variable to a new value.

workflow.setVariable("JobId", jobs);

workflow.setVariable("VAR_CLIENT", HostElements[0]);

workflow.setVariable("UPDATED_STATUS", true);

workflow.setVariable("requestorId", xpath:{/workflow/system/executor/userId});

workflow.setVariable("clientName", workflow.getInput("clientName"));

The following example is added to the OnComplete tab. The code puts the xpath value in a workflow-level variable:

if (xpath:{/workflow/PopupInput_8/deptValidation} != null && !xpath:{/workflow/PopupInput_8/deptValidation}.equals("")) {
workflow.setVariable("deptValidation", xpath:{/workflow/PopupInput_8/deptValidation});
logger.info("Setting deptValidation: [" + workflow.getVariable("deptValidation") + "]");
}
    

workflow.setLocalVariable(final String name, final Object obj)

Inside a process block, sets a local variable to a new value.

The variable is accessible inside the process block where it is defined.

workflow.setLocalVariable("local1","value1")

workflow.setLocalVariable("local2", xpath:{/workflow/CommServDBQuery_1/resultSets/row/col});

workflow.getLocalVariable(final String name)

Returns the current value of the local variable.

The variable is accessible inside the process block where it is defined.

workflow.getLocalVariable("local")

workflow.getOutput(final String name)

Returns the current value of the output.

workflow.getOutput("errorCode");

workflow.setOutput(final String name, final Object obj)

Sets the output to a new value.

workflow.setOutput("errorCode", 1);

workflow.getObject(final String xpath)

Returns the current value of the object.

workflow.getObject("/workflow/CollectAppList/resultSets[1]/row/col[1]");

workflow.setCompletionPercentage(percent complete)

Sets the percentage complete value for an activity.

workflow.setCompletionPercentage(40);

Was this page helpful?