Catalog client script is not working

shaikkhasim
Tera Contributor

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

 

1 ACCEPTED SOLUTION

AshishKM
Kilo Patron

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.

 

 

View solution in original post

6 REPLIES 6

Sandeep Rajput
Tera Patron

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

Harish Bainsla
Kilo Patron

Hi you can use below script but make changes as per your requirement .

HarishBainsla_0-1699431155371.png