Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
ServiceNow fix script to close an SCTASK and ensure the associated RITM is updated accordingly using
Solved! Go to Solution.
1 ACCEPTED SOLUTION
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi there @DeveloperG
Try this script
(function executeFixScript() {
var taskGR = new GlideRecord('sc_task');
taskGR.addQuery('state', '!=', '3');
taskGR.query();
while (taskGR.next()) {
taskGR.state = 3;
taskGR.work_notes = 'Closed by fix script.';
taskGR.update();
if (taskGR.request_item) {
var ritmGR = taskGR.request_item.getRefRecord();
var allClosed = true;
var checkTasks = new GlideRecord('sc_task');
checkTasks.addQuery('request_item', ritmGR.sys_id);
checkTasks.query();
while (checkTasks.next()) {
if (checkTasks.state != 3) {
allClosed = false;
break;
}
}
if (allClosed) {
ritmGR.stage = 'closed_complete';
ritmGR.work_notes = 'Closed automatically as all tasks are complete.';
ritmGR.update();
}
}
}
})();
If this helps do accept the solution thanks.
☑️ If this helped, please mark it as Helpful or Accept Solution so others can find the answer too.
Kind Regards,
Mohamed Azarudeen Z
Developer @ KPMG
Microsoft MVP (AI Services), India
Kind Regards,
Mohamed Azarudeen Z
Developer @ KPMG
Microsoft MVP (AI Services), India
5 REPLIES 5
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi there @DeveloperG
Try this script
(function executeFixScript() {
var taskGR = new GlideRecord('sc_task');
taskGR.addQuery('state', '!=', '3');
taskGR.query();
while (taskGR.next()) {
taskGR.state = 3;
taskGR.work_notes = 'Closed by fix script.';
taskGR.update();
if (taskGR.request_item) {
var ritmGR = taskGR.request_item.getRefRecord();
var allClosed = true;
var checkTasks = new GlideRecord('sc_task');
checkTasks.addQuery('request_item', ritmGR.sys_id);
checkTasks.query();
while (checkTasks.next()) {
if (checkTasks.state != 3) {
allClosed = false;
break;
}
}
if (allClosed) {
ritmGR.stage = 'closed_complete';
ritmGR.work_notes = 'Closed automatically as all tasks are complete.';
ritmGR.update();
}
}
}
})();
If this helps do accept the solution thanks.
☑️ If this helped, please mark it as Helpful or Accept Solution so others can find the answer too.
Kind Regards,
Mohamed Azarudeen Z
Developer @ KPMG
Microsoft MVP (AI Services), India
Kind Regards,
Mohamed Azarudeen Z
Developer @ KPMG
Microsoft MVP (AI Services), India