How to auto populate the logged in user details using onload client script

Sweety11
Kilo Contributor

Hi All,

I have a requirement where I have created multiple variables - RequestedFor, RequestedBy, Location, City, Country, MobileNumber, ManagerName and incidentLists

1.user opens the form above details auto populate with logged in user
2.on change of user, above details to be changed auto change based on the user change

3.incidenlists var only be visible on the form once the all the user details entered
4.populate all the list of incidents raised by selcted user - reqfor

Please help me to achieve this requirement

 

Thanks&Regards,

Sweety.

22 REPLIES 22

Sai25
Giga Guru

Hi ,

Please write the on change client script.

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

var gr = g_form.getReference('Requested_For',callBack);//update your variable name.
}
function callBack(gr){
g_form.setValue('Manager',gr.manager);
g_form.setValue('Location',gr.location);
g_form.setValue('Division',gr.department);


}

 

find_real_file.png

Sweety11
Kilo Contributor

Thanks for the response.

Can you please provide me the onload script for auto populating the current logged in user details.

Hey Sweety, 

This will work onload as well as onchange also.

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

if you wish to auto-populate when form loads then is it based on logged in user's location, city, country?

Regards
Ankur

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