Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

to close the incidents related to problem when problem is closed

Kushagra33
Tera Contributor

so i have a BR that i need to execute, the complete problem statement is:

 Write a business rule to resolve all the incidents associated with a problem ticket whenever the problem is Closed. Please copy the Fix Notes from Problem ticket to Incident Resolution Notes.

 

i have used after business rule with condition that state changes to closed on the problem table with this script:

(function executeRule(current, previous /*null when async*/) {

// Add your code here
var gd = new GlideRecord('incident');
gd.addQuery('problem_id', current.sys_id);
gd.query();
while(gd.next()){
gd.setValue('state','7');
gd.update();
}

})(current, previous);

 

can someone explain me the missing step as this isn't working, and an explanation too

2 ACCEPTED SOLUTIONS

Aman Kumar S
Kilo Patron

Hi @Kushagra33 ,

Hope your BR is After - Update - BR

Try below script:

 

I tried your script in a abackground script and this is the error that I received:

*** Script: INC0000048: State changed (On Hold->Closed), setting task to inactive
Slow business rule 'mark_closed' on incident:<span class = "session-log-bold-text"> INC0000048</span>, time was: 0:00:00.350
Slow business rule 'mark_resolved' on incident:<span class = "session-log-bold-text"> INC0000048</span>, time was: 0:00:00.295
Background message, type:error, message: Data Policy Exception: The following fields are mandatory: Resolution code, Close notes
*** Script: INC0000046: State changed (New->Closed), setting task to inactive
Slow business rule 'mark_closed' on incident:<span class = "session-log-bold-text"> INC0000046</span>, time was: 0:00:00.215
Slow business rule 'mark_resolved' on incident:<span class = "session-log-bold-text"> INC0000046</span>, time was: 0:00:00.126
Background message, type:error, message: Data Policy Exception: The following fields are mandatory: Resolution code, Close notes 

 

In order to close the incident you will need to Set the Resolution code and close notes as well .

Add the lines for that in your script and it would work.

 

var gd = new GlideRecord('incident');
gd.addQuery('problem_id', current.sys_id);
gd.query();
while(gd.next()){

gd.setValue("close_code", '');// pick a appropriate close code here

gd.setValue("close_notes", current.getValue("close_notes"));

gd.setValue('state','7');

gd.update();
}

 

Best Regards
Aman Kumar

View solution in original post

Valmik Patil1
Kilo Sage
5 REPLIES 5

Valmik Patil1
Kilo Sage

Hello,

Please visit below two links which can help you in above case

https://www.servicenow.com/community/developer-forum/when-problem-ticket-closed-then-related-inciden...

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0743796

 

Please let me know if you need any other help

Thanks,

Valmik Patil