- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2020 12:21 PM
Hi,
I have 2 variables in a variable set that I am using on a form. The first variable is requested_for using the type Requested For:
I have another variable manager.
All I need to do is populate that variable (manager) with the manager of the user in Requested For. This should be easy, however it is taking all day and I still cannot get it to work. I'm about to go insane.
Thanks in advance for any assistance.
Diana
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2020 01:18 PM
no... you need to create a catalog client script, not the regular client script. Instead of table, field you select variable set, variable. it should look more or less like this:

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2020 01:07 PM
Hello Diana,
Did you try the updated code? That should work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2020 01:31 PM
Hi,
I was not able to get it to work. However I was able to get tomaszienkiewicz's suggestion to work.
Thank you for all your help.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2020 12:55 PM
Hi, as I understand, you don't want to enforce the reference qualifier but rather set the value for the Manager variable dynamically, based on the Requested for variable.
To do this, you can create an onChange catalog client script, for the "Requested for" variable.
Make sure to remove the "isloading" part of the standard stop condition, as your Requested for will be populated on load automatically..
then you can do two things:
1) use the getReference method, e.g.
g_form.getReference('requested_for', callBack);
function callBack(requestor) {
g_form.setValue('manager', requestor.manager);
}
2. create a client-callable script include and call it from your client script via AJAX, the SI should return the sys_id of the manager which you can then populate in the Manager field same way as above.
The AJAX way is a bit better for performance as you are only pulling the sys_id from server to client, as oposed to getReference wich pulls the entire record, but you could just get away with getReference in this case 😉
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2020 01:03 PM
Hi,
Like I said I'm new to this. Does this look correct for the scirpt:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
g_form.getReference('requested_for', callBack);
function callBack(requestor) {
g_form.setValue('manager', requestor.manager);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2020 01:09 PM
More like this - on second thought, keep the "isLoading" part intact as the code might run twice.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
g_form.getReference('requested_for', callBack);
function callBack(requestor) {
g_form.setValue('manager', requestor.manager);
}
}
This assumes your variables have names requested_for, manager.
Also make sure you have the UI type set to where your script will actually run (desktop / portal)