Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

Script to cancel RITM but not close the same.

VIKAS45
Tera Guru

Please let me know the Script to cancel RITM but not close the same.

3 REPLIES 3

Tai Vu
Kilo Patron

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

Ankur Bawiskar
Tera Patron

@VIKAS45 

what did you start with and where are you stuck?

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

vermaamit16
Kilo Patron

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

Thanks and Regards
Amit Verma