Business rule that writes a variable form one ticket into the message of another ticket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2022 03:50 PM
Hello,
The scenario is this;
I have a catalog item in our Service Portal called Request Help. In this Request Help catalog item we ask for a reference ticket number. This reference ticket number would be an existing ticket in our ServiceNow instance. When a new Request Help catalog item is submitted I want to write this new ticket number into the reference ticket work notes.
I am able to do this in a Flow, but there is already a Flow attached to this catalog item.
So I think I need to do this with a business rule and a custom script, but my business rule script skills are minimal at best. Can anyone give me some tips, resources, or examples that might help.
Thank you,
Dan
- Labels:
-
Script Debugger
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2022 12:26 PM
Hi Dan,
(function executeRule(current, previous /*null when async*/) {
var ritm = current.variables.ticket; //replace 'ticket' with name of your ticket reference field
var ritmGr = new GlideRecord('sc_req_item'); //it's not creating a new RITM record, think of it as creating a new filter on the sc_req_item table
ritmGr.get(ritm); //query the table, to get the ritm record that has the sys id of the ritm that was provided in the forms reference field
if(ritmGr){ //After the table is queried, if there is a record that matches
ritmGr.work_notes= ''+current.number; //update that existing records work notes field with the current RITMs number(RITM created by request - the one that triggered this business rule -
ritmGr.update(); //update existing record to save changes
}
})(current, previous);
I've added some comments to each line in the script, hope that helps clear up what the script is doing.
in pseudo code it is:
- storing the sys id of the record that is in the ticket reference field on the form.
- Searching the sc_req_item table for a record with that sys id
- Updating that existing tickets work notes field with the new (Current) ritm number.
Hope that helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2022 12:47 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2022 02:47 PM
Oh yes,
Now that we have changed the table we are querying, we don't need to include the update(); method in the business rule.
Revised script:
(function executeRule(current, previous /*null when async*/) {
var ritm = current.variables.ticket; //replace 'ticket' with name of your ticket reference field
var ritmGr = new GlideRecord('sc_req_item');
ritmGr.get(ritm);
if(ritmGr){
ritmGr.work_notes= ''+current.number;
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2022 04:07 PM
Hello,
Sorry, I feel like I am really testing your good graces.
With that last update nothing happens.
I tested writing the ritmGr.number to the current.work_notes and that works, but it does not write current.number to ritmGr.work_notes.
Thank you.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2022 04:13 PM
No problem at all, might take a few tries to get it sorted.
Would you mind pasting the script you're using below and are you also using a Before business rule?
Thanks