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

Ankur Bawiskar
Tera Patron
Tera Patron

@sri vijaya 

you cannot dot walk to 2 levels

So you cannot fetch field values from User field on HR Profile as it's reference and you cannot dot walk to 1 more level

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

sri vijaya
Tera Contributor

Hi Ankur,

is there any other way like script include to concatination of 2 tables and glide ajax in catalog client script

Any suggestions please?

@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

Chetan Mahajan
Kilo Sage
Kilo Sage

Hello @sri vijaya ,

                              I would recommend to use GlideAjax here. you can refer this article for more details Client Side Scripting: Go for GlideAjax (with getXMLAnswer)! 

Kindly mark correct and helpful if applicable