- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 03:53 AM
Hi,
I have a requirement to close the RITMs with condition below using background/fix script
1.Catalog item specific = 'xyz'
2.Assignment group is empty
3.State is open/work in progress/pending
I need to write a background script to close the RITMs which contain above condition, Let me know how to write the script for this, I tried some code but it's not working
Thanks
Rashmi
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 04:10 AM
Hi,
Try this
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('cat_item', '<sys_id of catalog item>');
ritm.addQuery('state', 'IN', '-5,1,2');
ritm.addNullQuery('assignment_group');
ritm.query();
while (ritm.next()) {
ritm.state = 4;
ritm.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 04:10 AM
Hi,
Try this
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('cat_item', '<sys_id of catalog item>');
ritm.addQuery('state', 'IN', '-5,1,2');
ritm.addNullQuery('assignment_group');
ritm.query();
while (ritm.next()) {
ritm.state = 4;
ritm.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 04:33 AM
Hi Anurag,
Thank you very much, I tried this script in my instance, it works for me.
Regards,
Rashmi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2024 04:50 AM
You can easily build that query in a list view. Then copy the query. Then do this...
//store your copy and pasted query you got from the list view.
var myQuery = 'pasted query you copied from list view'
//instantiate a gliderecord variable.
var ritmGR = new GlideRecord ('sc_req_item');
//verify that the query is valid. SUPER important!
var validQueryCheck = ritmGR.isValidEncodedQuery(myQuery);
if (validQueryCheck){
ritmGR.addEncodedQuery(myQuery);
ritmGR.setValue('state', 4);
ritmGR.updateMultiple();
}
Some videos if you want to know more about addEncodedQuery and also why its essential to verify queries.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2025 11:59 PM
Hi @Rashmi N ,
It's better to go with the addEncodedQuery method in this case, because it has multiple conditions. Below is the working code to bulk close the RITM by building the query by forming the filter>run and copy query.