- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2023 10:25 PM
Need a script to check
If incident is marked as resolved
then
if resolved
all the incident task should be marked as closed complete
Cheers,
Jayaprakash
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2023 06:24 PM
(function executeRule(current, previous /*null when async*/) {
// Check if the incident has been moved to "Resolved" state
if (current.incident_state == '6') { // 6 represents "Resolved" state in ServiceNow
// Query all incident tasks related to this incident
var taskGr = new GlideRecord('incident_task');
taskGr.addQuery('incident', current.sys_id);
taskGr.query();
// Loop through incident tasks and close them
while (taskGr.next()) {
taskGr.setValue('incident_state', '7'); // 7 represents "Closed" state in ServiceNow
taskGr.setValue('close_code', 'Solved'); // You can set an appropriate close code
taskGr.update();
}
}
})(current, previous);
try the above sample code and adjust according to your requirement.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2023 09:28 PM - edited 09-02-2023 09:29 PM
Hello @jayaprakash1998 -
Please find below script that you can use in include function.
CloseTasks:Function(incRC){
var inc = new GlideRecord('incident');
inc.addQuery('sys_id',incRC);
inc.addQuery('state', '6'); //6 represents "Resolved" state of incident
inc.query()
if(inc.next()){
var inctask = new GlideRecord('incident_task');
inctask.addQuery('incident', inc);
inctask.query();
while(inctask.next()){
inctask.setValue('state', '7');//7 represents "closed complete" state of incident task
inctask.setValue('close_notes', 'solved');
inctask.update();
}
}
}
Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.
Thank You,
Rajesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2023 06:24 PM
(function executeRule(current, previous /*null when async*/) {
// Check if the incident has been moved to "Resolved" state
if (current.incident_state == '6') { // 6 represents "Resolved" state in ServiceNow
// Query all incident tasks related to this incident
var taskGr = new GlideRecord('incident_task');
taskGr.addQuery('incident', current.sys_id);
taskGr.query();
// Loop through incident tasks and close them
while (taskGr.next()) {
taskGr.setValue('incident_state', '7'); // 7 represents "Closed" state in ServiceNow
taskGr.setValue('close_code', 'Solved'); // You can set an appropriate close code
taskGr.update();
}
}
})(current, previous);
try the above sample code and adjust according to your requirement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2023 08:29 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2023 09:28 PM - edited 09-02-2023 09:29 PM
Hello @jayaprakash1998 -
Please find below script that you can use in include function.
CloseTasks:Function(incRC){
var inc = new GlideRecord('incident');
inc.addQuery('sys_id',incRC);
inc.addQuery('state', '6'); //6 represents "Resolved" state of incident
inc.query()
if(inc.next()){
var inctask = new GlideRecord('incident_task');
inctask.addQuery('incident', inc);
inctask.query();
while(inctask.next()){
inctask.setValue('state', '7');//7 represents "closed complete" state of incident task
inctask.setValue('close_notes', 'solved');
inctask.update();
}
}
}
Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.
Thank You,
Rajesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2023 08:39 PM