Populate the ‘location’ field on the incident form with the location of the Caller onLoad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 05:43 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 05:52 AM
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]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 06:52 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 08:11 AM
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.