Populate the email and phone of selected user in catalog item.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2023 03:47 AM - edited 02-03-2023 03:50 AM
Hi All,
I have requirement, like item variables are 'Register user, email and phone'. Register user variable is reference variable pointing to custom user table (note: not sys_user table). Custom User table has 'email' and 'phone' fields. In the portal, when I select the user then email and phone values should auto populate. I am trying with client script, it is not populating the values.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var req_for = g_form.getValue('requestor');
alert(req_for);
var details = new GlideRecord('u_users');
details.addQuery('sys_id', req_for);
details.query();
while (details.next()) {
alert('hello');
g_form.setValue('email', details.email);
alert(email);
}
}
Can any one help on this.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2023 04:44 AM
Hi @Krishna veni ,
You can use this solution :https://www.servicenow.com/community/developer-forum/how-to-auto-populate-mobile-number-and-email-id...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2023 05:53 AM
@Sandeep Dutta, I have tried with that code, but email is not populating. until step 15, it is working fine. after that it is not setting the value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2023 04:57 AM
@Krishna veni - Please try the below code snippet.
Please update the variable name and actual field name from your custom table in the script below
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.getReference('requestor', PopulateEmailandPhone); // PopulateEmailandPhone is our callback function
}
function PopulateEmailandPhone(requestor) { //reference is passed into callback as first arguments
g_form.setValue('email_variable_name', requestor.email);
g_form.setValue('phone_variable_name', requestor.phone);
}
Thanks & Regards,
Vasanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2023 05:58 AM
@Community Alums , I have tired with that code but after line no 15, it is showing error on browser and email is not populating.