How to update catalog item fields via client script using getReference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2018 10:16 AM
I have a field on the catalog item called requested_for which is a sys_user reference field.
I want to update the location field on the catalog item to the location of the requested for user - which is not necessarily the current logged in user. I have a catalog client script like below but the req4 is 'undefined' when I print to screen.
How can this be accomplished?
function onChange(control, oldValue, newValue, isLoading) {
if (newValue) {
var req4 = g_form.getReference('requested_for',mycallback);
}
return;
}
function mycallback(req4){
if(!isLoading && newValue != oldValue){
g_form.setValue('requested_for_location', req4.location);
}
}
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2018 11:02 AM
Try it like this:
function onChange(control, oldValue, newValue, isLoading) {
g_form.getReference('requested_for',mycallback);
}
function mycallback(caller) {
//Get location
var comp = caller.location;
g_form.setValue('company',comp);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2018 07:21 AM
Nope.
Here is the basic issue...
I am trying to capture the user referenced in the field 'requested_for'
In my catalog script I enter:
var req4 = g_form.getReference('requested_for',mycallback);
and then print to screen
g_form.addInfoMessage('Req4 is '+req4);
and I get back "req4 is undefined"
Am I capturing the sys_id incorrectly?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2018 07:32 AM
var req4 = g_form.getDisplayBox('requested_for').value;
g_form.addInfoMessage('Req4 is '+req4);
what exactly are you trying ? the sample code which michael has shared about the call back function is right.
but if you want to put the requested for name in info message then try with the script which i have shared.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2018 07:47 AM
Thanks but I used the code Michael supplied and it does not work for me.
I am trying to update the Requested_For location and manager fields on the catalog item when the requested_for user is changed. But I am having trouble getting the sys_id of the field into the script.
Here is the client script I have to set location field and nothing happens.
The field names have been double-checked. This is an onChange catalog client script.
--
function onChange(control, oldValue, newValue, isLoading) {
if (newValue) {
var req4 = g_form.getReference('requested_for',mycallback);
}
return;
}
function mycallback(req4){
if(!isLoading && newValue != oldValue){
var loc1 = req4.location;
g_form.setValue('requested_for_location', loc1);
}
}