- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2022 06:11 AM - edited 10-27-2022 06:13 AM
I have a catalog item that uses a reference field to pull in a user's name. I'm trying to use that reference to populate the userid into another field. I'm not sure what the syntax is for pulling the userid from that existing field. Here is the onchange script that I'm currently using. Any help would be awesome, gotta be something simple I'm missing (hopefully).
The first part works (pulling the name from the reference field and adding it to another field on change, but the userID part isn't working as I'm not sure what syntax to be using to pull it.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
}
var name = g_form.getDisplayValue('on_behalf_of');
g_form.setValue('requesters_name',name);
var netid = g_form.getDisplayValue('on_behalf_of.user_id');
g_form.setValue('requesters_netid',netid);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2022 06:53 AM
Hi,
I assume you are going set values for free form text variables.
can you try below script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var reqfor=g_form.getReference('requested_for_user',callback);
}
function callback(reqfor){
if(reqfor)
g_form.setValue('requester_user_name',reqfor.name);
g_form.setValue('requester_user_id',reqfor.user_name);
}
Thanks
Viswa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2022 06:28 AM
Hi!
I don't think the getDisplayValue takes any parameters. It will get the display value of the current record on the form:
You will need to get the reference of the on_behalf_of and the get the value of the user_name:
g_form.getReference('on_behalf_of').getValue('user_name');
I hope it helps!
Pedro
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2022 07:14 AM
this produces a javascript error on form load:
(g_env) [SCRIPT:EXEC] Error while running Client Script "Update Requester": TypeError: can't access property "getValue", g_form.getReference(...) is undefined
not sure if I maybe implemented it incorrectly?
var netid = g_form.getReference('on_behalf_of').getValue('user_name');
g_form.setValue('requesters_netid',netid);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2022 06:53 AM
Hi,
I assume you are going set values for free form text variables.
can you try below script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var reqfor=g_form.getReference('requested_for_user',callback);
}
function callback(reqfor){
if(reqfor)
g_form.setValue('requester_user_name',reqfor.name);
g_form.setValue('requester_user_id',reqfor.user_name);
}
Thanks
Viswa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2022 07:18 AM
this worked perfectly, thank you.