Change company access with roles

Filipe5
Kilo Expert

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.

find_real_file.png

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.

1 ACCEPTED SOLUTION

SumanthDosapati
Mega Sage
Mega Sage

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

View solution in original post

5 REPLIES 5

Glad that helped you 🙂