- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2014 01:38 PM
Is there a way to assign a role based on the user's location? So for all the users that have the value of "USA" in their Location field, grant the "usa_user" role. I think a script like the one below should work but I'm not sure where to put it.
var gr = new GlideRecord("sys_user");
gr.query();
while(gr.next()) {
if (gr.location == "USA") {
gr.roles = gr.roles + ",usa_user";
gr.update();
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2014 11:37 AM
gs.getUser().getLocation() == 'THE SYS_ID OF YOUR LOCATION HERE'
Remember, it's critical that your location sys_ids are consistent between instances so that you can use location data for permissions and security in this area (and many other built-in areas).
Please mark this as the answer to your question once you've confirmed that it works.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2014 01:41 PM
You'll need to add records to the 'sys_user_has_role' table using a GlideRecord insert in order to do that. You'll want to be careful though since role allocation usually comes with an additional license cost for each of those users. Why not just check their location instead of adding a duplicate attribute?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2014 02:14 PM
Well the end goal is to limit visibility of a UI Action form button I added to the incident form. It only works for US users so I am trying to hide it using the conditions field. Is there a way I can limit it's visibility based on current users location?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2014 03:11 PM
Absolutely. You can get any information from a user record and match against it. Getting a location value for a user is as simple as this...
gs.getUser().getLocation()
You could set that up in your condition to match against a specific sys_id value, just make sure that your sys_id values for locations are consistent across environments!
This guru article explains all of the different ways to get user information.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2014 11:32 AM