- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Dear All,
I am encountering an issue in ServiceNow where a recurring incident is being generated again and again despite of associated RITM already closed ,But the associated workflow is making the iterations again and again. Now provide me a background script which will query the specific RITM record and will terminate the workflow in ServiceNow. I have already applied one in TEST ,But wants to double check for assured execution.
Thanks,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi @SambitRath ,
for workflow use
var ritmGr = new GlideRecord('sc_req_item');
if (ritmGr.get('Put your RITM SYSID here'))
new global.Workflow().cancel(ritmGr);
for flow
var ritmSysId = 'e73818793b42c7509059bb0864e45a1d';
var grFlow = new GlideRecord('sys_flow_context');
grFlow.addQuery('source_record', ritmSysId);
grFlow.query();
while (grFlow.next()) {
gs.print('Cancelling Flow Context: ' + grFlow.sys_id);
sn_fd.FlowAPI.cancel(grFlow.sys_id.toString(), 'Cancelled via Background Script');
}
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
@SambitRath Please refer to this official documentation https://www.servicenow.com/docs/r/build-workflows/legacy-workflow/t_CancelingAWorkflow.html to know the steps to cancel a workflow.
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi @SambitRath ,
for workflow use
var ritmGr = new GlideRecord('sc_req_item');
if (ritmGr.get('Put your RITM SYSID here'))
new global.Workflow().cancel(ritmGr);
for flow
var ritmSysId = 'e73818793b42c7509059bb0864e45a1d';
var grFlow = new GlideRecord('sys_flow_context');
grFlow.addQuery('source_record', ritmSysId);
grFlow.query();
while (grFlow.next()) {
gs.print('Cancelling Flow Context: ' + grFlow.sys_id);
sn_fd.FlowAPI.cancel(grFlow.sys_id.toString(), 'Cancelled via Background Script');
}
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya