- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2022 08:21 PM
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
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2022 08:30 PM - edited 11-28-2022 08:33 PM
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();
}
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2022 08:34 PM
Hello,
Please visit below two links which can help you in above case
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2022 08:30 PM - edited 11-28-2022 08:33 PM
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();
}
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2022 08:48 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2022 08:53 PM
Awesome,
Feel free to mark correct if your issue is resolved and close the thread.
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2022 09:00 PM
You will need to Accept solution link on the correct response to close this.
Aman Kumar