Populate the ‘location’ field on the incident form with the location of the Caller onLoad

Philip Conforzi
Tera Contributor

Hello ServiceNow Community,

 

I hope you're doing well!

 

I am currently trying to automatically populate the 'location' field on the Incident form based on the location of the logged in user when the form loads. The problem is I haven't been able to get this to run successfully

 

I've created a client script and a script include which I've attached below.

 

Please let me know you r thoughts.

 

Thanks!

 

PhilipConforzi_1-1708436600326.png

 

 

PhilipConforzi_0-1708436582130.png

 

3 REPLIES 3

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Philip Conforzi 

Is logged in user is in caller field, if yes then, add the location field on form via dot walk and you work will be done. No need to write any code. 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Gustav Aldenbra
Kilo Sage

Hello @Philip Conforzi 

 

In your script include there is a typo. If you look at the class name you can see that you have named it "locationOnload" but on the second line you have "LocationOnLoad" If you uppdate the script include and change the first letter of the class to an uppercase L (first two lines and the type at the bottom) and also update the glideAjax in the client script to have an uppercase L it should work for you.

 

Ubada Barmawar
Giga Guru

Hi @Philip Conforzi 

 

looking into the fact that you want OnLoad Auto-populate, It is obvious that you want the location populated to be of current logged-in user.

we can use g_user object for this purpose, which returns the current logged-in user. 

 

hint : g_form.setValue('location', g_user.location);

please mark this accepted and helpful if it helps.

 

regards,

Ubada Barmawar.