Shamma Negi
Kilo Sage

Workflow

Workflow scripts provide an interface with the workflow engine.
Use these methods to manipulate workflows.
 
1. 

cancel(record)

Cancels all running workflows on this record by broadcasting the cancel event to activities in all running workflows on this record.
This is used to cancel the existing workflow attached to the record.

Example

 

 

//get workflow helper
      var workflow = new Workflow();
      //cancel all the workflows, where current is a task record with a workflow context
      workflow.cancel(current);
      gs.addInfoMessage(gs.getMessage("Workflows for {0} have been cancelled", current.getDisplayValue()));
2. restartWorkflow(GlideRecord current, Boolean maintainStateFlag)
Recalculates the approvals and tasks for a workflow by adding new approvals and tasks, while not resetting current approvals and tasks.

You can use this method to perform such tasks as adding a company to a change request, without resetting the current approvals for companies already in the workflow.

 

Example:

new Workflow().restartWorkflow(current, false);

 

3. 

startFlow(String workflowId, GlideRecord current, String operation, Array vars)

Starts a specified workflow.

You can also see the script include WorkflowScheduler and Business Rule "Start Workflow" on table sc_req_item for examples of use.

 

Example

 

 

////where current is a task record with a workflow context
      var w = new Workflow();
      var context = w.startFlow(id, current, current.operation(), getVars());

Hope this helps you.

 I hope this article helpful. Please mark it as helpful and bookmark if you like it.

 

Regards,

Shamma

2 Comments