- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2014 01:55 PM
How can I create a business rule, to be triggered when a new user is created (sys_user) and at creation time, a default role (alternatively a default group) is added to the new user?
Thanks.
Fernando.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2014 02:11 PM
Hi,
Write a BR on sys_user table, when to run: insert.
To add him to a group:
var gr = new GlideRecord('sys_user_grmember');
gr.initiate();
gr.user = current.sys_id;
gr.group = 'sys_id of the group you want to add the user to';
gr.insert();
OR to assign a role to him:
var gr = new GlideRecord('sys_user_has_role');
gr.initiate();
gr.user = current.sys_id;
gr.role = 'sys_id of the role you want to add the user to';
gr.insert();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2014 02:11 PM
Hi,
Write a BR on sys_user table, when to run: insert.
To add him to a group:
var gr = new GlideRecord('sys_user_grmember');
gr.initiate();
gr.user = current.sys_id;
gr.group = 'sys_id of the group you want to add the user to';
gr.insert();
OR to assign a role to him:
var gr = new GlideRecord('sys_user_has_role');
gr.initiate();
gr.user = current.sys_id;
gr.role = 'sys_id of the role you want to add the user to';
gr.insert();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2014 11:20 AM
Thanks Sumeet. That worked perfectly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2014 02:15 PM
Create a business rule with the following parameters:
Table: User [sys_user]
When: after
Insert: true
In the script, use GlideRecord to insert a new record into one of the following table:
sys_user_has_role (if you want to assign a role to the user)
sys_user_grmember (if you want to add the user into a group)
For detailed information on how to use GlideQuery, refer to the following Wiki article:
Using GlideRecord to Query Tables - ServiceNow Wiki
Blog: https://sys.properties | Telegram: https://t.me/sys_properties | LinkedIn: https://www.linkedin.com/in/slava-savitsky/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2014 11:22 AM
Thank you Slava. Your link about GlideRecord is very helpful.