Populate user related fileds like first name ,last name using catalog client script-HRProfile Table

sri vijaya
Tera Contributor

Hi

i am writing a catalog client script for auto populating user fields, whenever the user is changed the fields related to that user (ex; first ,last name should auto populate)which the fields are referencing to HR profile table in our case not the user table

its working fine for the customized fields which we designed in hr profile table(Title,project end date etc), but the OOTB fields which were already there in HR profile record like first name ,those were referencing to user table so the script is not working for these fields 

pasting the code here//

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

g_form.getReference('contractor_name', callBack);

function callBack(user) {

g_form.setValue(first_name,user.user.first_name);

g_form.setValue(last_name,user.user.last_name);
g_form.setValue('u_title', user.u_title);
g_form.setValue('u_project_end_date', user.u_project_end_date);
g_form.setValue('u_hire_date', user.u_hire_date);
g_form.setValue('u_person_type', user.u_person_type);
g_form.setValue('u_executive', user.u_executive);
g_form.setValue('u_remote', user.u_remote);
g_form.setValue('u_hiring_manager',user.u_hiring_manager);




}
}

@Ankur Bawiskar @Vaishnavi Lathk 

 

1 ACCEPTED SOLUTION

@sri vijaya 

please use GlideAjax and you can dot walk to multiple levels.

Return those values from script include and set in client side

Get User Details based on the Logged in user/ User selected in Client Script 

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

View solution in original post

5 REPLIES 5

Vaishnavi Lathk
Mega Sage
Mega Sage

Hello @sri vijaya ,

I Hope you are doing well!

 

you haven't Declare the variable for dot walk.

var user = g_form.getReference('contractor_name', callBack);

In the ServiceNow you cannot dot walk to 2 levels.Instead of that Refer GlideAjax as Mentioned by Ankur and Chetan.

 

FYR,

https://www.servicenow.com/community/developer-forum/autopopulate-user-details-onchange-of-user-name...

https://www.servicenow.com/community/developer-articles/get-user-details-based-on-the-logged-in-user...

https://www.servicenow.com/community/now-platform-forum/how-to-auto-populate-the-logged-in-user-deta...

 

Regards,

Vaishnavi Lathkar