
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2018 11:22 AM
Analysts are closing RITM's without closing the related Catalog tasks and the record remains in the Workflow contexts as active=true and state=executing. I created a business rule to prevent the analysts to close future RITMs without closing the respective task but now I need to go back to the previous RITM's and set the workflow to active=false and state=finished for all live workflows showing in the active context list.
I created a fix script and this is what I have so far - I'm having issues to query for the closed RITM in order to update the WF context. Please assist to fix this records.
// Look for WF records that have associated RITM records
// where the WF records are "active and executing"
var gr = new GlideRecord('wf_context');
gr.addEncodedQuery('active=true^state=executing');
// Query and change the output results
gr.query();
if(gr.next()){
gr.sc_req_item.current.wf.id.state="Closed Complete";
gr.autoSysFields(false);
gr.setWorkflow(false);
gr.setState = "Finished";
gr.update();
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2018 02:24 PM
Mike,
Thank you for your help, after trial and error, I'm going to use the following and I added the gr.active = "false"; at the end
// Look for WF records that have associated RITM records
// where the WF records are "active and executing"
// and the RITM record is not "active"
var gr = new GlideRecord('wf_context');
gr.addEncodedQuery('active=true^state=executing');
// Query and change the WF record to "false and Finished"
gr.query();
while(gr.next()){
if(gr.id.active==false){
gr.autoSysFields(false);
gr.setWorkflow(false);
gr.state = "Finished";
gr.active = "false";
gr.update();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2018 01:12 PM
try below
var gr = new GlideRecord('wf_context');
gr.addEncodedQuery('active=true^state=executing');
gr.query();
while(gr.next()){
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('sys_id', gr.id);
ritm.query();
if(ritm.next()){
if(ritm.state == 'Close Complete'){
gr.autoSysFields(false);
gr.setWorkflow(false);
gr.setState = "Finished";
gr.update();
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2018 02:24 PM
Mike,
Thank you for your help, after trial and error, I'm going to use the following and I added the gr.active = "false"; at the end
// Look for WF records that have associated RITM records
// where the WF records are "active and executing"
// and the RITM record is not "active"
var gr = new GlideRecord('wf_context');
gr.addEncodedQuery('active=true^state=executing');
// Query and change the WF record to "false and Finished"
gr.query();
while(gr.next()){
if(gr.id.active==false){
gr.autoSysFields(false);
gr.setWorkflow(false);
gr.state = "Finished";
gr.active = "false";
gr.update();
}
}