- 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 04:22 AM
Hello Shaik,
1: which type do you think is good is it Before BR or After BR
Adding the role I would definitely do this on BEFORE as you don't need to execute update(), doing it after may cause a loop as you are essentially updating the [sys_user] table AFTER it has already been updated.
With regards to adding the user to a group, it might be best to run this AFTER as you want to know a user is indeed a manager (and committed to database) before adding them to the group.
Further more to the BR, you might only want the BR to run if the "Title" changes. Also you may want to consider removing the role/group if the user "Title" no longer begins with "Manager".
2: If i want to run this script on existing user will it works ?
I don't see why not, you could query all users that have "Title" beginning with "Manager", then run pretty much the same script as your BR.
Always remember to TEST TEST TEST !!!
Kind regards,
Simon
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2017 06:07 AM
Thanks Simon i got your point. It helped me alot