We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Recurring Incident creation issue from Service Request.

SambitRath
Tera Contributor

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,

1 ACCEPTED SOLUTION

Chaitanya ILCR
Giga Patron

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

View solution in original post

2 REPLIES 2

Sandeep Rajput
Tera Patron

@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.

Chaitanya ILCR
Giga Patron

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