- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2022 08:53 AM
Hi everyone,
I need to give users in different departments access to specific companies. Usually this is achieved by adding that company to the user profile.
Considering the permissions often change - either because there are new companies or due to a specific company being assigned to another department, I question if it is possible to make these changes by creating roles for each department?
This way I would just need to change the role and all the users with that role would gain/lose access, instead of having to manually assign/remove companies from 300 user profiles.
Thanks in advance for your help.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2022 09:23 AM
Hi,
You can write a business rule to run when a role is added to user, then add the required company to user profile.
Business rule on sys_user_has_role table
Condition : After Insert
Script :
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', current.user);
gr.query();
if(gr.next())
{
if(current.role == 'sysid of role 1')
{
var listArr = gr.u_company.toString().split(',');//give company field backend name
listArr.push("sysid of group1"); //sysid of group you wanted to add for role 1
gr.setValue('u_company', listArr.join(','); //give company field backend name
gr.update();
}
else if(current.role == 'sysid of role 2')
{
var listArr = gr.u_company.toString().split(',');//give company field backend name
listArr.push("sysid of group2"); //sysid of group you wanted to add for role 2
gr.setValue('u_company', listArr.join(','); //give company field backend name
gr.update();
}
}
Mark as correct and helpful if it solved your query.
Regards,
Sumanth

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2022 03:31 AM
Glad that helped you 🙂