Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

How cancel a Playbook (sys_pd_context) via script.

Wesley Breshea1
Tera Contributor

Hello,

Needing to cancel a Playbook (sys_pd_context) via script.  Does anyone know the command or call to do so?  Also, not sure if canceling the parent will cancel or close out all the child Activity Executions (sys_pd_activity_context).  I found this script but determined it only works for Flow Designer, not Playbooks/Process Automation Designer.

 

var now_GR = new GlideRecord("sys_pd_context"); 
now_GR.addQuery("input_record", "Onboarding Case: ONB0001233"); 
now_GR.query();

while (now_GR.next()) { 
sn_fd.FlowAPI.cancel(now_GR.getUniqueValue(), 'Canceling Test Flows'); 
} 

 Tried @Ankur Bawiskar solution with no success either.

https://www.servicenow.com/community/itsm-forum/cancel-running-flow-contexts/m-p/609487

 

The goal is from a current running Playbook check if a value on the case record is 'true'; "No Migration".  If true, then cancel the associated sub-playbook so that it doesn't do migration activities.  Otherwise, allow that sub-playbook to be completed; "Perform Migration".

 

Thank you,

-Wesley

7 REPLIES 7

jigyasaarora23
Tera Contributor

Hi Wesley,

 

Let me know if you found a solution for this issue, I want to do a similar thing.

Markus9
Tera Contributor

We also had to cancel a few playbooks and did this with the following command:

 

sn_playbook.PlaybookExperience.cancelPlaybook(process, reason);

 

process --> gr of sys_pd_context
reason --> String

Hi @Markus9 , do you know if it's possible to restart a playbook via script? I'd like to restart playbooks of certain cases, but it has to be scripted. Any help would be appreciated!

Markus9
Tera Contributor

Hi @JordyZ,

 

unfortunately I am not aware of any restart function. You may be able to do it in two steps:

  1. Cancel the playbook execution (see answer above)
  2. Trigger the playbook again
sn_playbook.PlaybookExperience.triggerPlaybook(scopedName, parentRecord);

scopedName --> scoped name of the playbook
parentRecord --> record to initiate a playbook for