- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2017 03:02 AM
Hello Everyone,
I have a requirement where i need to grant ITIL roles to the users who has the Title as Manager.
We have a field called Title in User table if the field starts with Manager for them ITIL roles to be granted automatically.
can anyone please help me out regarding to this ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2017 03:33 AM
Hello Shaik,
The following line checks if the user has the role "self_service" and a "-1" means the user does NOT (value not found).
if (gr.accumulated_roles.toString().indexOf(",self_service,") == -1) {
If you want to add a user to a group, the code is a little bit more complex as you would need to utilise "GlideRecord". Don't forget to check if the user is already part of the group before adding them in.
- //Create a new group relationship record for this user
- var rec1 = new GlideRecord('sys_user_grmember');
- rec1.initialize();
- rec1.user = current.sys_id;
- rec1.group.setDisplayValue('Asia Group');
- rec1.insert();
Kind regards,
Simon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2017 03:09 AM
Hello Shaik,
You could achieve this is a Business Rule on the [sys_user] table.
Using the "current" variable, check if the field "Title" starts with "manager" then grant the "ITIL" role using a script.
Can you refer to the following documentation on how to write the script for adding the role.
Kind regards,
Simon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2017 03:25 AM
Thanks Simon,
That helps
Can you please explain me below line ?
if (gr.accumulated_roles.toString().indexOf(",self_service,") == -1)
And let me add 1 more point we created a Group named as ITIL can i use below script if i want to add group name instead of role name ?
gr.group= gr.group+ ",ITIL";
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2017 03:33 AM
Hello Shaik,
The following line checks if the user has the role "self_service" and a "-1" means the user does NOT (value not found).
if (gr.accumulated_roles.toString().indexOf(",self_service,") == -1) {
If you want to add a user to a group, the code is a little bit more complex as you would need to utilise "GlideRecord". Don't forget to check if the user is already part of the group before adding them in.
- //Create a new group relationship record for this user
- var rec1 = new GlideRecord('sys_user_grmember');
- rec1.initialize();
- rec1.user = current.sys_id;
- rec1.group.setDisplayValue('Asia Group');
- rec1.insert();
Kind regards,
Simon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2017 04:15 AM
Simon,
it helped me but i have couple of questions,
1: which type do you think is good is it Before BR or After BR
2: If i want to run this script on existing user will it works ?