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

Community Alums
Not applicable

@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.

Krishnaveni_0-1675432406872.png

 

Vasantharajan N
Giga Sage
Giga Sage

@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

Krishna veni
Tera Contributor

@Community Alums , I have tired with that code but after line no 15, it is showing error on browser and email is not populating.

Krishnaveni_0-1675432686645.png