- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2020 03:11 AM
Hi All,
I have used the below script for closing the change request associated with the ritm,
var gr2 = new GlideRecord('sc_request');
gr2.addActiveQuery();
gr2.addQuery('sys_id','***********');
gr2.query();
while(gr2.next()){
gr2.request_state ='closed_cancelled';
gr2.state =4;
gr2.stage ='closed_incomplete';
gr2.update();
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request','********');
ritm.query();
while(ritm.next()){
var chg = new GlideRecord('change_request');
chg.addQuery('parent','#######3');
chg.query();
chg.state=7;
chg.update();
while(chg.next()){
var workflow = new Workflow();
workflow.cancel(chg);
}
ritm.update();
}
}
The workflow is getting cancelled but the state of the change request is not getting updated.
Thanks in advance.
Regards,
Devika.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2020 09:39 PM
Thanks for marking my response as helpful.
Let me know if I have answered your question.
If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2020 03:46 AM
Hi there,
What are you trying to achieve here? Can you explain?
var chg = new GlideRecord('change_request');
chg.addQuery('parent','#######3');
chg.query();
chg.state=7;
chg.update();
That part looks odd to me. Not performing a chg.next for example, if(chg.next), etc..
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2020 04:00 AM
Hi,
update as below; you should put those 2 lines inside the while
I assume you are having state with value as 7 for your change_request table
var gr2 = new GlideRecord('sc_request');
gr2.addActiveQuery();
gr2.addQuery('sys_id','***********');
gr2.query();
while(gr2.next()){
gr2.request_state ='closed_cancelled';
gr2.state =4;
gr2.stage ='closed_incomplete';
gr2.update();
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request','********');
ritm.query();
while(ritm.next()){
var chg = new GlideRecord('change_request');
chg.addQuery('parent','#######3');
chg.query();
while(chg.next()){
chg.state=7;
chg.update();
var workflow = new Workflow();
workflow.cancel(chg);
}
ritm.update();
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2020 09:39 PM
Thanks for marking my response as helpful.
Let me know if I have answered your question.
If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2020 09:41 PM
Hi there,
Any input on my response?
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field