How to populate First and last name on the basis of email

Arsh Agnihotri
Tera Contributor

HI Everyone,

 

How to populate First and last name on the basis of email selected in Catalog Item.

I have created script include (via javascript object) and client script but I am getting wrong first name and last name, every time its showing virtual agent however emaild id is empty for virtual agent user.

 

 Script Include:

ArshAgnihotri_0-1740032047918.png

Client script:

ArshAgnihotri_1-1740032119589.png

I am getting below data:

 

ArshAgnihotri_2-1740032242972.png

 

Please help me guys.

 

Thanks in advance 🙂

 

Thanks!

Chhavi Agnihotri

 

 

 

 

 

4 REPLIES 4

Murthy Ch
Giga Sage

Hi @Arsh Agnihotri 

Did you keep logs in server side script and see which user record is returning?

Hope you are given the correct variable name for email.

Thanks,
Murthy

Sandeep Rajput
Tera Patron
Tera Patron

@Arsh Agnihotri Looks like the name of your email field is incorrect. It seems that line number 6 in your client script is returning empty value hence the query in script include is fetching a record where email is empty.

 

var userEmail=g_form.getValue('email'); //Please veify if the email is the correct name for the email field on the form.

Ankur Bawiskar
Tera Patron
Tera Patron

@Arsh Agnihotri 

I could see Email is a reference variable then why not use auto populate feature with no scripting

Auto-populate a variable based on a reference type variable (Utah) 

Since your variable is reference you should query with sysId and not email

Update this line in script include

user.addQuery('sys_id', email);

Also in GlideAjax update this line as this

ga.addParam('sysparm_email' , newValue);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Arsh Agnihotri 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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