- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2017 07:13 AM
Hi All,
I want the current user's location in the service portal page. I used the below code
HTML:
{{data.location}}
and in the Server Script:
data.location = gs.getUser().getLocation();
Below is the error I get-
Server JavaScript error Cannot find function getLocation in object com.glide.script.fencing.ScopedUser@1166b0e.
Please let me know how can we use these functions in scoped applications?
Thanks in advance,
Jessie
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2017 07:50 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2017 07:16 AM
Hi Jessie,
I haven't checked on this one specifically, but the message is telling me that you cannot use getLocation() in the widget. You may have to do this with a GlideRecord query from the sys_user table. Keep in mind that getLocation() would have returned a sys_id to the cmn_location table as will the location field on sys_user. You'll likely want to get the display value of that field if you are going to use it in {{data.location}}
Let me know if you need specifics on the GlideRecord stuff.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2017 07:31 AM
Hi Jessie,
I actually just ran into something similar, so I had a code snippet ready for it:
var user = new GlideRecord('sys_user');
if (user.get(gs.getUser().getID())) {
data.location = user.getValue('location');
}
You can get a more list of what's available to the scoped GlideUser object here:
https://developer.servicenow.com/app.do#!/api_doc?v=istanbul&id=c_GlideUserScopedAPI
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2017 07:45 AM
Hi Brad,
Thank you so much for the quick reply. I tried your above code and I am not getting the error now. However the location returns sys_id and getDisplayValue() doesn't work. Any idea?
Regards,
Jessie

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2017 07:50 AM
Oh ok. Try data.location = user.location.getDisplayValue();