auto populate email id when name is selected from the reference field(sys_user)

Sneha39
Mega Guru

auto populate email id when name is selected from the reference field(sys_user)

Form fields

Name(reference from sys_user)

email( to be populate)

tried client script on variable set but its not working,

 

Kindly help with this simple script.

 

Thanks

1 ACCEPTED SOLUTION

dvp
Mega Sage
Mega Sage

Here is an onChange catalog client script

Please update the variable names in the below script

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading) {
      return;
   }


   var usr = g_form.getReference('USER_VARIABLE_NAME', callBack);
	
}

function callBack(usr)
{

	g_form.setValue('EMAIL_VARIABLE_NAME', usr.email);


}

View solution in original post

10 REPLIES 10

dvp
Mega Sage
Mega Sage

Here is an onChange catalog client script

Please update the variable names in the below script

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading) {
      return;
   }


   var usr = g_form.getReference('USER_VARIABLE_NAME', callBack);
	
}

function callBack(usr)
{

	g_form.setValue('EMAIL_VARIABLE_NAME', usr.email);


}

Perfect!  I knew there had to be a simple solution

asifnoor
Kilo Patron

Hi Senha,

Create a onchange client script on your Name field.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}

//Type appropriate comment here, and begin script below
var caller = g_form.getReference('your_name_field', getEmail); // doAlert is our callback function }
  function getEmail(caller) { //reference is passed into callback as first arguments
    g_form.setValue('your_email_field',caller.email,caller.email);
  }
}

PS: you need to change the field names to yours.

Mark the answer as correct once it worked.

 

answer is correct