Issue with Catalog Client Script to set location
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 07:08 AM
Hi All,
I have an issue with my Catalog Client Script related to set the location in Single Line Text variable based on user's location from another variable ('requested_for')
Currently it looks like:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var affectedUser = g_form.getReference('requested_for', doAlert);
function doAlert(affectedUser) {
if (affectedUser) {
g_form.setValue('requested_for_location', affectedUser.location);
}
}
}
and it was working fine my 'requested_for_location' field was a Reference field not a SIngle Line Text field.
When it is a Single Line Text filed then it gives me a sys_id value,,
Do you know how can I chnage the script to receive 'normal' string value in this Single Line Text field?
Thanks in advance for help!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 07:17 AM
Hi @Kasia5
Try this:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var affectedUser = g_form.getReference('requested_for', doAlert);
function doAlert(affectedUser) {
if (affectedUser) {
g_form.setValue('requested_for_location', affectedUser.getDisplayValue('location'));
}
}
}
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 07:21 AM
Hi @Kasia5 ,
Can u try using this
g_form.getDisplayBox('<field name>').value;
Please mark my answer helpful & accepted if it resolves your query.
Regards,
Danish Bhairagdar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 07:31 AM
you cannot dot walk 2 level using getReference and also getDisplayValue() I doubt won't work in client side.
So you need to use GlideAjax only as the last option
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
09-21-2023 07:36 AM
Hi @Ankur Bawiskar,
I thought that as well, but it just works 😄
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.