I need to set value in reference variable based on other reference variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2022 03:40 AM
Hi All,
I need to set value in reference variable based on other reference variable.
Below is the client script in log i can see the value but it's not set in reference varible.
function onChange(control, oldValue, newValue, isLoading) {
if(isLoading || g_form.getValue('device_name')!= '')
{
var mn = g_form.getReference('device_name', callback);
}
}
function callback(mn) {
g_form.setValue('device_serial', mn.serial_number);
alert('Value='+ mn.serial_number);
}
Please suggest.
Thanks all.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2022 03:49 AM
Hi If both values are Reference to the same table, this will not work.
In the first variable you have a sys_id, which is the reference to the device record you want. The second variable expects the same thing. Instead, you are passign a string value, which is the mn.serial_number. If this is not a valid sys_id of a record in the table you are referencing, this is not going to work.
Please Mark Correct and Helpful if my answer helps you resolve your issue. Thanks!
Martin Ivanov
Community Rising Star 2022
Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2022 04:44 AM
It looks like you want to populate the second variable with the serial number of the device that's selected in the first variable. Since you're getting the correct (string) value in your alert, you would just need to change the type of the second variable to Single Line Text. If you need to use the serial number of the selected device to reference a record on another table that corresponds to the second variable, then you would want to scrap the getReference approach and change to a GlideAjax call where you can retrieve the serial number then use it in a GlideRecord to query the other table and return that record all in one trip to the server.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2022 09:26 AM
Hi Thanks for reply,
if you need to use the serial number of the selected device to reference a record on another table that corresponds to the second variable ?
Ans : i need to use the serial number of the selected device to reference a record on same table that corresponds to the second variable.
Can you provide the any script that will papulate the value in reference variable.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2022 06:58 AM
If both variables reference the same table, I'm assuming the use case is something like you want to return the record that has the same serial number but is a different record/device? You would need a GlideAjax call in the Client Script to do this - there are many examples of this around the community.
The Script Include would do a GlideRecord query on the referenced table, given the sys_id passed in from the client script. This will give you the serial number, then you can do another GlideRecord query on the same table using the serial number and excluding the first result/sys_id to return the record that has the same serial number - or whatever your use case is, then you would return this result (sysid) to the client script for the setValue.