- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2023 08:18 AM
Hi!
I have a record producer I am working on where a user can select the building name (common_building_name | reference field for table A) of their choosing. After the user submits their form, this building name is supposed to map to the "location" field on the work order created (location | which is a different reference field for table B).
Since they are both different tables, I checked each one and saw both tables had the 'name' field with the same building names so I tried using:
1. current.location = producer.common_building_name
- this did not work, I thought maybe since the variable name was inside a Variable Set that I had to add that before the variable name...
2. current.location = producer.ritm_common_building_set.common_building_name
- this also didn't work. I had some other values that needed to map from the same variable set and found you did not need the variable set infront of the variable name for it to work, so #1 should have worked but it doesnt.
3. current.location = 'sys_id of common building name'
- didn't work
4. current.location = producer.common_building_name.getDisplayValue()
- also did not work.
At this point I am stuck. Is there a way to successfully do this within the record producer script? or do I have to create a function? and if I do, can anyone point me to resources on how to get this started?
I provided pictures below. Please note that address' are also the same for both tables, but I have blurred them out.
Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2023 10:16 AM
Hi Amy,
A reference field or variable stores the sys_id of the selected record. Since the reference variable is referencing the Building table, your attempts with the simple assignment logic have been trying to use that sys_id to find the same sys_id on the Location table, which will not happen. You can do a quick GlideRecord inside this script to find the Location record where the Name matches the Name of the selected building:
var loc = new GlideRecord('cmn_location');
loc.addQuery('name', producer.common_building_name.name);
loc.query();
if (loc.next()) {
current.location = loc.sys_id;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2023 10:16 AM
Hi Amy,
A reference field or variable stores the sys_id of the selected record. Since the reference variable is referencing the Building table, your attempts with the simple assignment logic have been trying to use that sys_id to find the same sys_id on the Location table, which will not happen. You can do a quick GlideRecord inside this script to find the Location record where the Name matches the Name of the selected building:
var loc = new GlideRecord('cmn_location');
loc.addQuery('name', producer.common_building_name.name);
loc.query();
if (loc.next()) {
current.location = loc.sys_id;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2023 12:15 PM
Thank you! this worked for me 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2023 05:24 AM
