Fix script to update multiple records
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2020 02:06 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2020 02:25 PM
Hi Kam,
You can use the below script:
var gr = new GlideRecord('sc_req_item');
gr.addEncodedQuery('state=4^active=false');
gr.setLimit(5);//this will update only 5 records only for testing purpose, please remove this line so that all the records will be updated at once
gr.query();
while(gr.next()){
var gr2=new GlideRecord('sc_request');
gr2.addActiveQuery();
gr2.query();
if(gr2.next()){
gr2.setValue('state','value_of_state_you_want_to_set');//4 is the value for closed incomplete and 3 for complete
gr2.update();
}
}
remove setLimit piece of code to update the record at once.
Kindly mark my answer as Correct and Helpful based on the Impact.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2020 02:29 PM
Thanks Chaitanya
How do we validate before we execute this ? i mean instead of Update at first time how do print how many of there

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2020 02:57 PM
Sorry provided you the wrong code, give me a moment and will update you with the correct one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2020 03:40 PM
With the below script all the request which are active but all child RITM is in active false state will be changed to inactive and Closed Complete.
var gr=new GlideRecord('sc_request');
gr.addActiveQuery();
gr.query();
while(gr.next()){
var gr2 = new GlideRecord('sc_req_item');
gr2.addQuery('request',gr3.getUniqueValue());
gr2.addActiveQuery();
gr2.query();
if(!gr2.next()){
gr.setValue('state','3');//set the value as closed complete
gr.setValue('request_state','closed_complete');
gr.update();
}
}