How do you cancel a Playbook that was triggered for a SIR record when a second Playbook is triggered, so that they are not both running simultaneously?

Vincent13
Tera Expert

For example, Playbook A is triggered, then the SIR record's Category changes, which triggers Playbook B. When this happens, I want Playbook A to stop running.

1 ACCEPTED SOLUTION

Vincent13
Tera Expert

SOLUTION: almost all of my Playbook Triggers are based on SIR Category field...

I created a before Update Business Rule, when Category changes on SIR record.

Script:

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var now_GR = new GlideRecord("sys_flow_context");
	now_GR.addQuery("source_record", current.sys_id);
	now_GR.query();
	
	while (now_GR.next()) {
		sn_fd.FlowAPI.cancel(now_GR.getUniqueValue(), "Previous Flow has been canceled");
	}
	
	var oldTask = new GlideRecord("sn_si_task");
	oldTask.addQuery("parent", current.sys_id);
	oldTask.query();
	
	while (oldTask.next()) {
		oldTask.state = 7; //State value 7 = Canceled
		oldTask.update();
	}

})(current, previous);

View solution in original post

2 REPLIES 2

Brad W1
ServiceNow Employee
ServiceNow Employee

Vincent,

I think this KB will help you.

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0750702

You'll want to be sure to include the correct conditions on the Business Rule that you create.

Brad

Vincent13
Tera Expert

SOLUTION: almost all of my Playbook Triggers are based on SIR Category field...

I created a before Update Business Rule, when Category changes on SIR record.

Script:

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var now_GR = new GlideRecord("sys_flow_context");
	now_GR.addQuery("source_record", current.sys_id);
	now_GR.query();
	
	while (now_GR.next()) {
		sn_fd.FlowAPI.cancel(now_GR.getUniqueValue(), "Previous Flow has been canceled");
	}
	
	var oldTask = new GlideRecord("sn_si_task");
	oldTask.addQuery("parent", current.sys_id);
	oldTask.query();
	
	while (oldTask.next()) {
		oldTask.state = 7; //State value 7 = Canceled
		oldTask.update();
	}

})(current, previous);