- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2022 05:04 AM
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.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2022 05:35 AM
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
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2022 08:56 AM
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();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2022 05:35 AM
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
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2022 08:56 AM
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();
}