Script to cancel RITM but not close the same.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2024 10:25 PM
Please let me know the Script to cancel RITM but not close the same.
3 REPLIES 3
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2024 10:37 PM
Hi @VIKAS45
If you're using Workflow, you can use the API below.
cancel(GlideRecord record)
//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()));
If you're using Flow Designer, you can leverage this FlowAPI.
cancel(String contextId, String reason)
var now_GR = new GlideRecord("sys_flow_context");
now_GR.addQuery("source_table", "sc_req_item");
now_GR.addQuery("source_record", "<the_requested_item_sys_id>"); //Your RITM
now_GR.query();
while (now_GR.next()) {
sn_fd.FlowAPI.cancel(now_GR.getUniqueValue(), 'Canceling Test Flows');
}
Cheers,
Tai Vu
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2024 10:42 PM
what did you start with and where are you stuck?
Regards,
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2024 11:38 PM
Hi @VIKAS45
Please try the below code snippet :
var gr = new GlideRecord('sc_req_item');
// Sys ID of your RITM
gr.addQuery('sys_id','17a59f742fef75902b86d4a72799b675');
gr.query();
if(gr.next()){
gr.state = '4' ;
gr.update();
}
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.