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 04:28 PM
Hi,
It is very much just the code you gave me with the ticket changed. Yes, runing in a business rule. Whether it is set to before or after doesn't seem to make a difference.
(function executeRule(current, previous /*null when async*/) {
var ritm = current.variables.reference_ticket_add_hr_or_deployment_ticket_number_here;
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-18-2022 05:30 AM
I have it working with an AFTER business rule and the following script (same as before but this time using After and update()):
(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);
Please give this a try, if it doesn't work you may have a restriction on the RITM number field or something else causing an issue with duplicate keys
Hope this helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2022 09:03 AM
Hello,
For some reason this just does not work in my ServiceNow instance. Adding the update() also did not work and I have seen a lot of comments and documents that say not to use it.
I will have to find another way.
Thanks for all your help.