Client Scripts

Phani Pasupulet
Tera Contributor

There are 2 tables 
sys_user 
s1(custom table)

PhaniPasupulet_0-1690793666722.png

here user is referencing the sys_user table
I want to auto populate email when user was selected 
I have written some code but it is not working why....?
Can anyone help

PhaniPasupulet_1-1690794060742.png

 

PhaniPasupulet_2-1690794092647.png

 

 

PhaniPasupulet_3-1690794149155.png

 

 



 

2 ACCEPTED SOLUTIONS

Aman Kumar S
Kilo Patron

Hi @Phani Pasupulet ,

I would suggest using GlideAjax, as getReference has performance impacts.

Even if you choose to use GetReference, use it with callback function.

var user = g_form.getReference('u_reference_4', getEmail); // doAlert is our callback function } 
function getEmail(user) { //reference is passed into callback as first arguments
 g_form.setValue('u_string_2',user.email);
}
Best Regards
Aman Kumar

View solution in original post

Ankur Bawiskar
Tera Patron
Tera Patron

@Phani Pasupulet 

Why not add the email field as Dot walked field on form fromt he User Name field and make it readonly?

Then no script is required

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Aman Kumar S
Kilo Patron

Hi @Phani Pasupulet ,

I would suggest using GlideAjax, as getReference has performance impacts.

Even if you choose to use GetReference, use it with callback function.

var user = g_form.getReference('u_reference_4', getEmail); // doAlert is our callback function } 
function getEmail(user) { //reference is passed into callback as first arguments
 g_form.setValue('u_string_2',user.email);
}
Best Regards
Aman Kumar

Ankur Bawiskar
Tera Patron
Tera Patron

@Phani Pasupulet 

Why not add the email field as Dot walked field on form fromt he User Name field and make it readonly?

Then no script is required

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Phani Pasupulet
Tera Contributor

PhaniPasupulet_0-1690796119964.png
I auto populated ph no 
why I am gettting number as above format

even when I updating the abel number it is taking in the same format

 

@Phani Pasupulet 

Ph no is of what type? It looks it's string type.

The format comes based on how it's stored in sys_user record

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader