- 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 08:05 AM
Hi there,
You are not sharing anything.
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2024 08:12 AM
Hello Mark,
i am new to ServiceNow Development. i am practicing in my PDI some scenarios
i have written a script for incident task creation when incident created my code is working as expected. but in the same way i am trying to set incident closed when all incident tasks are closed. could you please share with me script how to set automatically inc state as closed
 
					
				
		
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2024 08:15 AM
Please share what you tried and is not working.
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2024 08:37 AM
i have written above script with the reference of below community article.
