- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 01:08 PM
Hi everyone!
I would like to ask your assistance, I have this requirement when a new user is added to the sys_users table I need them automatically added to the PM submitter group. I created a business rule but it is not automatically adding new users. Any suggestions on what the best practice to achieve this would be.
thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 10:09 PM
Hello @Gemma4 ,
What I observed in the First screenshot, You added Group as PM Submitter, but you forgot to add the User field with the value from Trigger->User Record
Please check the Second Screenshot from my Answer
I hope this clears your question
Please mark my answer helpful and correct, If it helps you
Thank you
Thank you
G Ramana Murthy
ServiceNow Developer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 12:16 AM - edited 09-22-2023 12:17 AM
Dear Gemma,
@Gemma4 , hope you're doing great!
Sample Business Rule:
// Business rule
function onAfter(current, previous) {
// Get the PM submitter group.
var group = GlideRecord('sys_user_group');
group.get('name', 'PM submitter');
// Add the new user to the group.
var groupMember = GlideRecord('sys_user_grmember');
groupMember.initialize();
groupMember.user = current.sys_id;
groupMember.group = group.sys_id;
groupMember.insert();
}
This business rule will be triggered after a new user is added to the sys_users table. The business rule will then get the PM submitter group and add the new user to the group.
To attach the business rule to the sys_users table, follow these steps:
- Navigate to System Administration > Business Rules.
- Click the New button.
- Enter a name and description for the business rule.
- Select the Table that you want to apply the business rule to. In this case, you would select the sys_users table.
- Select the Condition that you want to use to trigger the business rule. In this case, you would select the After condition and the Insert event.
- Select the Action that you want to perform when the business rule is triggered. In this case, you would select the Insert action and the sys_user_grmember table.
- Click the Save button.
Once you have attached the business rule to the sys_users table, new users will be automatically added to the PM submitter group when they are added to the sys_users table.
TIPS:
- Test your business rules thoroughly before deploying them to production. Make sure that the business rules are working as expected and that they are not causing any unexpected behavior.
- Document your business rules so that you can easily revert to the original configuration if needed.
- Use a version control system to manage your business rules. This will help you to track changes to your business rules and to recover from any problems.
Kindly, please mark my solution as Helpful/Correct, if applicable. If I could help you with your Query then, please hit the Thumb Icon and mark as Correct!!!
Thanks & Regards,
Revanth. K
Product Test Automation Engineer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 02:17 PM
Thank you for all the details but unfortunately the user did not get automatically added to the group. Under the "actions" step I can not add a different table. When I add sys_user_grmember it automatically saves as sys_user. Perhaps this is the issue? See attached.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 01:01 AM - edited 09-22-2023 01:04 AM
Hello @Gemma4,
We can do it with Flow Designer with two simple steps
1. You need to create a Trigger Create Record on User [sys_user] table.
2. Create an action Create Record under trigger
Table should be Group Member [sys_user_grmember]
Fields
User - Drag sys_id data pill Trigger -> User Record -> sys_id (You can drag entire User Record data pill from Tigger)
Group - <select your required group, PM Submitter in your case
Save and Active your Flow, It works as you expected.
Please mark this as correct and helpful, if it resolves your query.
Thank you
Thank you
G Ramana Murthy
ServiceNow Developer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 02:19 PM
I added the flow and feel we are really close to resolving this. Unfortunately when the user is added, the record is displaying as empty? see attached. Not sure why the userid is not getting copied.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 10:09 PM
Hello @Gemma4 ,
What I observed in the First screenshot, You added Group as PM Submitter, but you forgot to add the User field with the value from Trigger->User Record
Please check the Second Screenshot from my Answer
I hope this clears your question
Please mark my answer helpful and correct, If it helps you
Thank you
Thank you
G Ramana Murthy
ServiceNow Developer