Update related Problems, incident or case work notes with close code and close notes of a Change Req

Abimbola
Tera Expert

Hi All,

The requirement is -

when a change request is closed, the related problem, incident or case work notes should be updated with: 

"change <change number> has been closed with the following closure information: close code<close_code> and close notes <close_notes>."

 

I am creating an after business rule on the change request table with 

condition: state is closed

 

Having trouble getting the script right (particularly how to reference the related records (INC, PROB, CASE) in the GlideRecord Query. would appreciate your help with the script.

 

Thanks.

2 ACCEPTED SOLUTIONS

Ahmmed Ali
Mega Sage

Hello @Abimbola 

 

Try below script:


//Update incidents
var grinc = new GlideRecord("incident");
grinc.addActiveQuery();
grinc.addQuery("rfc", current.sys_id);
grinc.addNotNullQuery("rfc");
grinc.query();
while(grinc.next()){
	grinc.close_notes = "YOUR_NOTES_VALUE";
	grinc.close_code = "YOUR_CODE_VALUE";
	grinc.update();
}

//update problem record
var grprb = new GlideRecord("problem");
grprb.addActiveQuery();
grprb.addQuery("rfc", current.sys_id);
grprb.addNotNullQuery("rfc");
grprb.query();
while(grprb.next()){
	grprb.close_notes = "YOUR_NOTES_VALUE";
	grprb.close_code = "YOUR_CODE_VALUE";
	grprb.update();
}

//update Case table (update table name and field name which holds change request number)
var grcase = new GlideRecord("CASE_TABLE_NAME");
grcase.addActiveQuery();
grcase.addQuery("FIELD_NAME_WHICH_HOLDS_CHANGE_REQUEST", current.sys_id);
grcase.addNotNullQuery("FIELD_NAME_WHICH_HOLDS_CHANGE_REQUEST");
grcase.query();
while(grcase.next()){
	grcase.close_notes = "YOUR_NOTES_VALUE";
	grcase.close_code = "YOUR_CODE_VALUE";
	grcase.update();
}

 

Thank you,

Ali

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

View solution in original post

Abimbola
Tera Expert

Thank you @Ahmmed Ali .

Your response was very helpful. I modified the update part of the script you provided and inputed the case table name and used same "rfc" as field name for the case query. It worked perfectly!😁

 

See modified script below:

 

var grinc = new GlideRecord("incident");
grinc.addActiveQuery();
grinc.addQuery("rfc", current.sys_id);
grinc.addNotNullQuery("rfc");
grinc.query();
while(grinc.next()){
grinc.work_notes = 'Change ' + current.number + ' has been closed with the following closure information:' + ' Close Code is ' + current.close_code + " and Close Notes is " + current.close_notes;
grinc.update();
}

var grprb = new GlideRecord("problem");
grprb.addActiveQuery();
grprb.addQuery("rfc", current.sys_id);
grprb.addNotNullQuery("rfc");
grprb.query();
while(grprb.next()){
grprb.work_notes = 'Change ' + current.number + ' has been closed with the following closure information:' + ' Close Code is ' + current.close_code + " and Close Notes is " + current.close_notes;
grprb.update();
}

var grcase = new GlideRecord("sn_customerservice_case");
grcase.addActiveQuery();
grcase.addQuery("rfc", current.sys_id);
grcase.addNotNullQuery("rfc");
grcase.query();
while(grcase.next()){
grcase.work_notes = 'Change ' + current.number + ' has been closed with the following closure information:' + ' Close Code is ' + current.close_code + " and Close Notes is " + current.close_notes;
grcase.update();
}

View solution in original post

2 REPLIES 2

Ahmmed Ali
Mega Sage

Hello @Abimbola 

 

Try below script:


//Update incidents
var grinc = new GlideRecord("incident");
grinc.addActiveQuery();
grinc.addQuery("rfc", current.sys_id);
grinc.addNotNullQuery("rfc");
grinc.query();
while(grinc.next()){
	grinc.close_notes = "YOUR_NOTES_VALUE";
	grinc.close_code = "YOUR_CODE_VALUE";
	grinc.update();
}

//update problem record
var grprb = new GlideRecord("problem");
grprb.addActiveQuery();
grprb.addQuery("rfc", current.sys_id);
grprb.addNotNullQuery("rfc");
grprb.query();
while(grprb.next()){
	grprb.close_notes = "YOUR_NOTES_VALUE";
	grprb.close_code = "YOUR_CODE_VALUE";
	grprb.update();
}

//update Case table (update table name and field name which holds change request number)
var grcase = new GlideRecord("CASE_TABLE_NAME");
grcase.addActiveQuery();
grcase.addQuery("FIELD_NAME_WHICH_HOLDS_CHANGE_REQUEST", current.sys_id);
grcase.addNotNullQuery("FIELD_NAME_WHICH_HOLDS_CHANGE_REQUEST");
grcase.query();
while(grcase.next()){
	grcase.close_notes = "YOUR_NOTES_VALUE";
	grcase.close_code = "YOUR_CODE_VALUE";
	grcase.update();
}

 

Thank you,

Ali

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

Abimbola
Tera Expert

Thank you @Ahmmed Ali .

Your response was very helpful. I modified the update part of the script you provided and inputed the case table name and used same "rfc" as field name for the case query. It worked perfectly!😁

 

See modified script below:

 

var grinc = new GlideRecord("incident");
grinc.addActiveQuery();
grinc.addQuery("rfc", current.sys_id);
grinc.addNotNullQuery("rfc");
grinc.query();
while(grinc.next()){
grinc.work_notes = 'Change ' + current.number + ' has been closed with the following closure information:' + ' Close Code is ' + current.close_code + " and Close Notes is " + current.close_notes;
grinc.update();
}

var grprb = new GlideRecord("problem");
grprb.addActiveQuery();
grprb.addQuery("rfc", current.sys_id);
grprb.addNotNullQuery("rfc");
grprb.query();
while(grprb.next()){
grprb.work_notes = 'Change ' + current.number + ' has been closed with the following closure information:' + ' Close Code is ' + current.close_code + " and Close Notes is " + current.close_notes;
grprb.update();
}

var grcase = new GlideRecord("sn_customerservice_case");
grcase.addActiveQuery();
grcase.addQuery("rfc", current.sys_id);
grcase.addNotNullQuery("rfc");
grcase.query();
while(grcase.next()){
grcase.work_notes = 'Change ' + current.number + ' has been closed with the following closure information:' + ' Close Code is ' + current.close_code + " and Close Notes is " + current.close_notes;
grcase.update();
}