The CreatorCon Call for Content is officially open! Get started here.

Service Portal - Cannot find function getLocation

Jesi Perinbaraj
Kilo Contributor

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

1 ACCEPTED SOLUTION

Oh ok. Try data.location = user.location.getDisplayValue();


View solution in original post

6 REPLIES 6

Chuck Tomasi
Tera Patron

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.


Brad Tilton
ServiceNow Employee
ServiceNow Employee

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


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


Oh ok. Try data.location = user.location.getDisplayValue();