- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2024 08:02 AM
Hello Folks,
I have a requirement on incident form, i want to close incident automatically when all associated incident tasks are closed. How can we do this with scripting. i tried with After Business rule but my script not working as expected. any help would be appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2024 08:31 AM
HI @Jaya Chandra Re ,
Write a After Update BR on incident task table
when to run: state changes to closed complete
Script:
(function executeRule(current, previous /*null when async*/ ) {
var inc_task = new GlideRecord('incident_task');
inc_task.addQuery('incident', current.incident);//field where incident is captured
inc_task.addQuery('active', true);//check if any tasks are active
inc_task.query();
if (inc_task.next()) {
//do nothing
//you can also print any info message if you want
} else {
var inc = new GlideRecord('incident');
inc.addQuery('sys_id', current.incident);
inc.query();
if (inc.next()) {
inc.state = 6; //close state
inc.close_code = 'successful';
inc.close_notes = "Auto-Closed based on Incident Tasks being Closed"; //while closing incident check if there are any mandatory fields and pass value to those so that the script works
inc.update();
}
}
})(current, previous);
Please mark my answer helpful/correct if it resolved your query
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2024 09:50 AM
In your script under if statement change the variable name of updation
inc.update() to Inc_Gr.update();
Also remove the else part it is not needed
Please mark my answer helpful/correct if it resolved your query
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2024 09:58 AM
It's my fault. After updating its working fine.