Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Populate the email and phone of selected user in catalog item.

Krishna veni
Tera Contributor

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.

Krishnaveni_0-1675424770263.png

 

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.

 

5 REPLIES 5

christophenow
Tera Expert

The "new" right way to do this is to use the "Auto-populate" functionality available since Utah release.

In your variable form, you have a tab "Auto-populate" with 3 fields:

Dependent question : Choose the reference variable (in your case "Requestor")

Reference : filled automatically with the related table (in your case, sys_user)

Dot walk path : Choose the field that contains the value you want to populate (in your case, Requestor.Email)

 

More information here.

https://www.servicenow.com/community/developer-articles/auto-populate-a-variable-based-on-a-referenc...

 

No need to script anymore 😉

 

If usefull, please mark as helpful.