- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 06:40 AM - edited 08-21-2023 06:42 AM
An issue reported, whenever multiple incidents are related to a Problem ticket (PRB) the work notes should generate in PRB as: gr.number + " has been associated with this problem ticket." with correct incident no. . Each time when a new incident no is related to PRB the work notes do genertate but with incorrect incident number.
We have a onBefore Business rule in place with condition : Related incidents changes (Operation- Update).
The code snipnet as follows:
(function executeRule(current, previous /*null when async*/) {
// gs.addInfoMessage('current.problem_id');
var gr = new GlideRecord('incident');
gr.addQuery('problem_id', current.sys_id);
gs.info('Running problem '+ current.sys_id.getDisplayValue());
gr.query();
if(gr.next()){
gs.info('Running incident '+ gr.number);
current.work_notes= gr.number + " has been associated with this problem ticket.";
// current.update();
}
})(current, previous);
Pls help with correct code snipet or hint. Thanks!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 07:10 AM
@Ashish Gupta8 Please update your BR script as follows.
(function executeRule(current, previous /*null when async*/) {
// gs.addInfoMessage('current.problem_id');
var gr = new GlideRecord('incident');
gr.addQuery('problem_id', current.sys_id);
gs.info('Running problem '+ current.sys_id.getDisplayValue());
gr.orderByDesc('sys_updated_on'); //This will fetch the latest updated incident with problem reference.
gr.query();
if(gr.next()){
gs.info('Running incident '+ gr.number);
current.work_notes= gr.number + " has been associated with this problem ticket.";
// current.update();
}
})(current, previous);
Hope this helps.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 07:10 AM
@Ashish Gupta8 Please update your BR script as follows.
(function executeRule(current, previous /*null when async*/) {
// gs.addInfoMessage('current.problem_id');
var gr = new GlideRecord('incident');
gr.addQuery('problem_id', current.sys_id);
gs.info('Running problem '+ current.sys_id.getDisplayValue());
gr.orderByDesc('sys_updated_on'); //This will fetch the latest updated incident with problem reference.
gr.query();
if(gr.next()){
gs.info('Running incident '+ gr.number);
current.work_notes= gr.number + " has been associated with this problem ticket.";
// current.update();
}
})(current, previous);
Hope this helps.