JavaScript API Reference/Ab.workflow.Workflow object

runRuleAndReturnResult(workflowRuleId, parameters, timeout)

Call specified workflow rule, wait until the execution is finished and returns the WFR result object back to the caller. The workflow rule is executed in synchronous mode, i.e. the runRule() function does not return to the caller until after the workflow rule execution is finished and the result is received.

Returns: the workflow rule Result object that contains:

  • code : WFR execution code, one of following values:
    •  'executed': WFR was successfully executed
    •  'ruleNotFound': WFR with specified ID does not exist
    •  'ruleNotPermitted': the user has no permission to execute the WFR
    •  'ruleFailed': WFR code has failed
    •  'containerFailed': internal server error while executing the WFR
    •  'sessionTimeout': the user session has timed out; this result code automatically redirects the browser to the Login page
  • message : text message that either can be returned from the workflow rule  (optional, depends on the workflow rule), or contains an error message if the workflow rule execution failed
  • jsonExpression : serialized JSON object returned by the workflow rule (optional, depends on the workflow rule)
  • data : de-serialized JSON object returned by the workflow rule (optional, depends on the workflow rule)
  • xmlDocument : serialized XML document returned by the workflow rule (optional, depends on the workflow rule).


Parameters:

  • workflowRuleId (String): workflow rule ID
  • parameters (JS object): input parameters to be sent to the workflow rule; this object can contain:
    •  simple properties, such as strings or numbers
    •  other objects or arrays (that can contain other objects or arrays), encoded in JSON notation
  • timeout (integer): (optional) timeout in seconds

Example:

Call a workflow rule without parameters:

var result = Workflow.runRuleAndReturnResult('AbCommonResource-getUser', {});
if (result.code == 'executed') {
var userName = result.data.user_name;
}