- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2019 06:06 AM
auto populate email id when name is selected from the reference field(sys_user)
Form fields
Name(reference from sys_user)
email( to be populate)
tried client script on variable set but its not working,
Kindly help with this simple script.
Thanks
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2019 06:10 AM
Here is an onChange catalog client script
Please update the variable names in the below script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
var usr = g_form.getReference('USER_VARIABLE_NAME', callBack);
}
function callBack(usr)
{
g_form.setValue('EMAIL_VARIABLE_NAME', usr.email);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2022 12:13 AM
May I know why you gave two times caller.email in setValue?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2019 06:18 AM
One more thing to add i forgot to select variable name while applying this script on variable set so it wasn't working.( This was a reason as well) Just in case if above script is not working for anyone.
Thanks dvp

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2019 06:19 AM
If the issue is resolved, kindly mark the comment as correct and helpful so that the question is removed from the unanswered list.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2019 06:21 AM
Hi Sneha,
You can try using the below function
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var _user = g_form.getValue('name');
var userGR = new GlideRecord('sys_user');
userGR.addQuery('sys_id', _user);
userGR.query();
if(userGR.next())
{
g_form.setValue('email', userGR.email);
}
}
'name' & 'email' is to be replaced by your username & email variables respectively.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2021 07:58 AM
this is not working in the portal, any idea why??