Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

How to set worknotes of Incident from Business rule on Problem

Gayathri5
Tera Guru

Hi 

 

(function executeRule(current, previous /*null when async*/ ) {
var gp = new GlideRecord('problem');
gp.addQuery('sys_id', current.sys_id);
gp.query();
while (gp.next()) {

}

var gr = new GlideRecord('incident');
gr.addQuery('problem_id', gp.sys_id);
gr.query();

while (gr.next()) {

gr.setValue('u_cause_code', '14');
gr.setValue('description', 'set from problem BR');

 gr.setValue('work_notes','Incident closed by'+ gp.number);

gr.update();
}
})(current, previous);

I am trying set the work_notes in a similar way but it is not working.

I want to set my worknotes as "Incident closed by PRBxxxxx";

How can we set Incident worknotes in the above code?

Regards,

Gayathri

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

update as this which is optimized

(function executeRule(current, previous /*null when async*/ ) {

	var gr = new GlideRecord('incident');
	gr.addQuery('problem_id', current.getUniqueValue());
	gr.query();
	while (gr.next()) {
		gr.setValue('u_cause_code', '14');
		gr.setValue('description', 'set from problem BR');
		gr.work_notes = 'Incident closed by' + current.number;
		gr.update();
	}

})(current, previous);

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

5 REPLIES 5

Raghu Ram Y
Kilo Sage

Hi,

Try like below..

gr.work_notes = 'Incident closed by'+ gp.number;

If still not working...

then add the below line after while (gp.next()) {

var number = gp.number; 

 

 

Next, after gr.setValue line add below line

gr.work_notes = 'Incident closed by'+number;

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

update as this which is optimized

(function executeRule(current, previous /*null when async*/ ) {

	var gr = new GlideRecord('incident');
	gr.addQuery('problem_id', current.getUniqueValue());
	gr.query();
	while (gr.next()) {
		gr.setValue('u_cause_code', '14');
		gr.setValue('description', 'set from problem BR');
		gr.work_notes = 'Incident closed by' + current.number;
		gr.update();
	}

})(current, previous);

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi,

 

It is working.

current.sys_id and current.getUniqueValue() both will fetch sys_id na, we can use any right?