How to get the value of the 'location' field from sys_user tale using client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2019 09:58 PM
Hi All ,
I have written a catalog client script to populate the values of the user id logged into the off boarding form . However the user.location field is coming as null. The 'location' field is coming as 'https://dev78523.service-now.com/com.glideapp.servicecatalog_cat_item_view.do?v=1&sysparm_id=4dcaf086db227300100384da0b961990'
Can someone please help me fix it ? I have used DisplayBox.value but it was not working. Below is the code used onLoad
function onLoad() {
var user = g_form.getReference('requested_for',populateReqForDetails);
function populateReqForDetails(user) {
alert(user.location);
g_form.setValue('location',user.location);
alert(location);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2019 10:00 PM
Hi,
Is your requested_for already populated when form is loaded? what value you are getting in the alert of user.location?
function onLoad() {
var user = g_form.getReference('requested_for',populateReqForDetails);
function populateReqForDetails(user) {
alert(user.location);
g_form.setValue('location',user.location);
}
}
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2019 11:18 PM
Hi Ankur ,
Yes , requested_for is populated onLoad. I am getting null for the alert(user.location).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-18-2019 08:13 AM
Hi,
Can you try to give alert for requested_for variable?
also does that user have location populated in user table?
function onLoad() {
alert(g_form.getValue('requested_for'));
var user = g_form.getReference('requested_for',populateReqForDetails);
function populateReqForDetails(user) {
alert(user.location);
g_form.setValue('location',user.location);
}
}
Also check the user with which you are testing is having access to location table i.e. cmn_location.LIST
see whether it shows records or not or read ACL is blocking the data for that user
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2019 11:32 PM
Hi Synthia,
Can you try below client script:
function onLoad(){
var user = g_form.getReference('requested_for',doAlert); // doAlert is our callback function
}
function doAlert(caller) { //reference is passed
alert(user.location);
if (user.location != ''){
g_form.setValue('location',user.location);
}
}