- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 06:17 PM
Hi Team
i have created a catalog client script
i have created two fields, user name and email ..my requirement is , if i select the user , email should be auto populate in email filed
user name (type is reference)
email (type singline text)
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var userid=g_form.getValue('user_name');
var grv=new GlideRecord('sys_user');
gr.addQuery('sys_user',userid);
gr.query();
while(gr.next())
{
g_form.setValue('email',grv.email);
}
Regards
Khsaim
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 06:21 PM - edited 11-07-2023 06:46 PM
Hi @shaikkhasim
Please correct the result set name use either gr or grv.
and update the addQuery parameter it should be “sys_id” not the “sys_user”.
use the updated code:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var userId=g_form.getValue('user_name');
var grv=new GlideRecord('sys_user');
grv.addQuery('sys_id', userId);
grv.query();
// use if condition as only one user will match the sys_id record
if(grv.next())
{
g_form.setValue('email',grv.email);
}
-Thanks
AshishKMishra
Please accept solution and mark helpful for others if it helps you.
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2023 10:28 PM
@shaikkhasim You should update your onChange client script as follows.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var userid=g_form.getReference('user_name',callback);
function callback(caller){
g_form.setValue('email',caller.email);
}
}
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2023 12:12 AM
Hi you can use below script but make changes as per your requirement .