The CreatorCon Call for Content is officially open! Get started here.

Duplicated entries in work notes by business rule with glide record query

Piotr Ba_amut
Giga Expert

Use case: when closing an INC X , other incidents with the same Short Description as an INC X should have appended a string to the work notes that INC X has been closed. 

Issue:  there are appended few entries to the work notes instead of one only. 

Code: 

(function executeRule(current,previous) {

var INCnumber = current.number;
var gr = new GlideRecord('incident');
gr.addQuery('active',true);	
gr.addQuery('short_description','=',current.short_description);
//gr.addQuery('state',7);	
gr.query();
	
while(gr.next()) {
	
	gr.state.getValue(7);
	gr.work_notes = "Please note that incident " +INCnumber+  " with the same Short Description has been closed";
	gr.update();
	   }
} ) (current,previous);

find_real_file.png

1 ACCEPTED SOLUTION

HI Sir,

 

Can you mark answer as correct and close this thread so that everyone can use it.

 

Thanks,
Ashutosh

View solution in original post

3 REPLIES 3

Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi,


Use below code:

 

var INCnumber = current.number;

var gr = new GlideRecord('incident');

gr.addQuery('active',true);

gr.addQuery('sys_id','!=',current.sys_id);

gr.addQuery('short_description','=',current.short_description); //gr.addQuery('state',7);

gr.query();

while(gr.next()) {

gr.state.getValue(7); g

r.work_notes = "Please note that incident " +INCnumber+ " with the same Short Description has been closed"; gr.update();

}

 

Thanks,
Ashutosh Munot

Thanks, Buddy. Is working well now.

HI Sir,

 

Can you mark answer as correct and close this thread so that everyone can use it.

 

Thanks,
Ashutosh