Incorrect incident no update in work notes of PRB ticket.

Ashish Gupta8
Tera Contributor

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!

 

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@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.

View solution in original post

1 REPLY 1

Sandeep Rajput
Tera Patron
Tera Patron

@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.