Fix script to close req and Ritm if sc tasks are closed complete / incomplete
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2024 10:25 PM
Hi All,
I have tried to implement a fix script to check if the tasks are closed complete/incomplete and move forward to close the respective RITM and Request. This is the script I have and it is not working properly.
var taskGr = new GlideRecord('sc_task');
taskGr.addEncodedQuery('stateIN3,4');
taskGr.query();
while (taskGr.next()) {
var gr1 = new GlideRecord('sc_req_item');
gr1.addQuery('request.state=1^stateIN1,2^cat_itemISEMPTY');
//gr1.addEncodedQuery('numberSTARTSWITHRITM1186392');
gr1.query();
while (gr1.next()) {
gr1.state = taskGr.state;
if (taskgr.state == 4) {
gr1.approval = "rejected";
gr1.state = "closed_rejected";
gr1.stage = "incomplete";
} else if (taskgr.state == 3) {
gr1.approval = "approved";
gr1.state = "closed_complete";
gr1.stage = "completed";
}
gr1.update();
}
}
Can anyone help me on this please.
Thank you.
5 REPLIES 5
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2024 11:17 PM
Hi @Vasavi O ,
If you use nested GlideRecords in your code it can lead to performance issue, yet better way is to keep your code clean and use dotwalking as you are working with fix scripts i.e.. server side scripts.
Here the the code below, make sure to make custom changes in the like encodedQuery, backend value of complete state.
var task = new GlideRecord('sc_task');
task.addEncodedQuery('numberSTARTSWITHTASK0000001'); // add you encoded query here to filter complete/incomplete task.
task.query();
while(task.next()){
task.request_item.state = '3'; // set req_item state as closed complete
task.request_item.request.state = '3'; // set request state as closed complete
task.update();
}
Thanks,
Hope this helps you.