- 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-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-11-2014 11:54 AM
Do I have to use the Sys ID? Is there a way I can just use the actual value? I'm also going to have to add a OR statment to it and I have to add a handful of locations

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2014 12:22 PM
Unless you want to create a custom script include to return that, or populate a separate field on the user record to indicate that the user is in one of the locations you want, you'll have to use a sys_id.