- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2025 09:15 AM
I have the need to update the contents of a variable when the field on TableXYZ changes.
I have created a BR that runs when Field A on TableXYZ changes and I am trying to get it to copy the value from Field A to a variable on the RITM linked to the record in TableXYZ, but it does not appear to be working:
I have configured the following BR on Table XYZ and I added a log statement to troubleshoot, but my glide record keeps coming back as undefined
When to Run: When is After, Update is True, Filter Conditions are when field A changes
Script:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
you want to update variable with Field A value.
But in your script you are setting package_description field on Table XYZ
Assumptions
-> if your variable name is package_description and field u_requested_item holds RITM sysId then use this script
-> if your variable is string type and package_description on Table XYZ is also string type
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var gr = new GlideRecord('sc_item_option_mtom');
gr.addQuery('request_item', current.u_requested_item);
gr.addQuery('sc_item_option.item_option_new.name', 'package_description');
gr.query();
if (gr.next()) {
var itemOptionRec = gr.sc_item_option.getRefRecord();
itemOptionRec.value = current.package_description;
itemOptionRec.update();
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
Hi @leport ,
I have modified your code. If you follow my new code and replace the sys_id of your variable & field name then you can achieve this requirement.
Note: Please check my code before using this code
Here the code:
Prashant
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
you want to update variable with Field A value.
But in your script you are setting package_description field on Table XYZ
Assumptions
-> if your variable name is package_description and field u_requested_item holds RITM sysId then use this script
-> if your variable is string type and package_description on Table XYZ is also string type
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var gr = new GlideRecord('sc_item_option_mtom');
gr.addQuery('request_item', current.u_requested_item);
gr.addQuery('sc_item_option.item_option_new.name', 'package_description');
gr.query();
if (gr.next()) {
var itemOptionRec = gr.sc_item_option.getRefRecord();
itemOptionRec.value = current.package_description;
itemOptionRec.update();
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
Hi @leport ,
I have modified your code. If you follow my new code and replace the sys_id of your variable & field name then you can achieve this requirement.
Note: Please check my code before using this code
Here the code:
Prashant
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
Thank you! I ended up adding the following script to a BR on the source table: