- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2022 06:04 AM
I have a form in the scoped app.
The requested for field gets auto-populated when I use this in the default field
But for the location field it is not working
what is wrong with the javascript code
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2022 06:24 AM
Hi @rahul16
Yes it will only work in global application. It won't work for scoped application.
SO, please try below logic in default value field:
javascript: var loc; var gr=new GlideRecord("sys_user"); gr.addQuery("sys_id",gs.getUserID()); gr.query(); if(gr.next()) { loc=gr.location;} loc;
See below screenshot for your reference:
Hope it helps..
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2022 06:15 AM
Hi @rahul16 ,
gs.getUser().getLocation(); should fetch you with the correct location details.
Check if the user(rahul p) which you are referring has "Location" in it's user record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2022 06:18 AM - edited 10-07-2022 06:19 AM
yes it has a location I created the form in the scoped app not global app does it work only on global
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2022 06:28 AM
HI @rahul16 ,
Just like gs.getUser().getDepartmentID() , for Location also , i don't think it works for Scoped App and gs.getUser().getLocation(); would work for Global Scope.
For scoped App, you will require a custom a custom Table to store the location, then you can refer it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2022 06:24 AM
Hi @rahul16
Yes it will only work in global application. It won't work for scoped application.
SO, please try below logic in default value field:
javascript: var loc; var gr=new GlideRecord("sys_user"); gr.addQuery("sys_id",gs.getUserID()); gr.query(); if(gr.next()) { loc=gr.location;} loc;
See below screenshot for your reference:
Hope it helps..
Murthy