Using Data Returned from Workflow Rules
Using Data Returned from Workflow Rules
In advanced applications the workflow rule services can
return custom data values to be either displayed or used in JS code. Just
like custom input parameters, the service output parameters are
returned using JSON format. To execute a service and obtain its output parameters,
the JS code can use the
Workflow.call()
method:
var result = Workflow.call('AbProjects-approve', parameters);
The
Workflow.call()
method always waits for the service execution to be finished, and
then obtains the service output parameters. The output parameter
values are returned as a part of the
result
object. The result object contains following properties:
-
code
: service execution result code; if the service was executed successfully, the value is 'ruleExecuted
'; -
message
: the optional text message returned from the service; if the service has failed, this will contain the detailed error message; -
data
: contains service output parameters as JavaScript objects or arrays; -
dataSet
: service may pass output parameters in the form of a DataSet object; DataSet can represent a single record, a list of records, a one-dimensional or a two-dimensional MDX array of records; see ab-core/controls/ab-data.js for details of the DataSet objects; -
xmlDocument
: contains service output parameters in the XML format (optional, is available only if the service outputs its results in the XML format).
If the service needs to return a single string value to the JS
code, it can use the
message
property.
In all other cases the preferred approach is to return values in the JSON
format, as it can efficiently transfer complex objects and properties.
Here is an example of using JSON output parameters:
var result = Workflow.call('AbProjects-approve', parameters);
if (result.code == 'executed') {
var data = result.data;
// the result data can include simple properties...
var projectStatus = data.status;
// complex objects with nested properties...
var projectId = data.project.project_id;
// or arrays of objects
var firstActionItem = data.project.action_items[0];
}
Examples
Event handler that uses data returned from the workflow rule |
\parts\programming\each\ab-ex-echo.js |