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

Hi @Markus9 , it worked! I've been stuck on this issue for days, thank you so much.

Hi @Markus9  , Where do we need to run this line of code!? Cant we run this in background script? 

Markus9
Tera Contributor

Yes, just run this as background script 🙂