Script for checking open catalog tasks in a RITM and not close the RITM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2023 08:58 PM
Hi Community,
I am trying to write a fix script to close the RITM which has all the catalog tasks closed and not close the RITM if it has at least one catalog task open. Please help me troubleshoot, it's not checking the catalog task open when the script is run.
Below is the script I am using -
var Closedcomplete = 0;
var grSCtask = new GlideRecord('sc_task');
grSCtask.addEncodedQuery('active=false'); //<-- whatever you want to filter on
grSCtask.query();
while (grSCtask.next()) {
if(grSCtask.parent != grSCtask.request_item){
grSCtask.parent = grSCtask.request_item;
grSCtask.update();
}
var grRITM = new GlideRecord('sc_req_item');
grRITM.addQuery('sys_id', grSCtask.request_item);
grRITM.query();
var count = grSCtask.getRowCount();
while(grRITM.next()) {
if(grSCtask.state == '3'){
Closedcomplete += 1;
}
if (Closedcomplete == count) {
grRITM.state = '3';
grRITM.stage = 'complete';
grRITM.setWorkflow(false);
grRITM.update();
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2023 11:55 PM
I just ran the same above script and it updated around 1000+ records in DEV. not sure what am I missing. Have you checked the changes I made on your script to update the encoded query.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2023 12:00 AM
Hello @Varun Sai
Because of this line it's updating your all the sc_tasks
while (grSCtask.next()) {
grSCtask.parent = grSCtask.request_item;
grSCtask.update();
Please remove this -
grSCtask.parent = grSCtask.request_item;
grSCtask.update();
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2023 12:04 AM
Ohhh, okay!
So where can I include that line
grSCtask.parent = grSCtask.request_item; grSCtask.update();
as I need it to update the Parent with the respective RITM# that's why I have this line to query.
grSCtask.addEncodedQuery('active=false^parentSTARTSWITHchg');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2023 12:08 AM
Hello @Varun Sai
If you will use this
active=false^parentSTARTSWITHchg
Then it will update all the sc_task's which will having above query satisfied.
So please do this later use the code without doing sc_task updation.
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.