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

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

Ok thanks for the suggestion, i have fixed the 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('close_code','Resolved by problem');
gd.setValue('close_notes', current.fix_notes);
gd.setValue('state','7');
gd.update();
}

})(current, previous);

this is working for my test problem and related incident in created 

Awesome,

Feel free to mark correct if your issue is resolved and close the thread.

 

 

Best Regards
Aman Kumar

You will need to Accept solution link on the correct response to close this.

 

Best Regards
Aman Kumar