Business rule to add user to group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2023 09:15 AM
Hello Guys,
I have created a true/false field on the Customer_Contact table labelled "u_non_standard_request_authorised" I am looking for a way to add the user of the record to a group I have created "Non-Standard Request Authorised" when the value is set to true.
I am assuming a business rule is the best route here but not sure where to begin. I assume a rule that monitors Customer_Contact records and triggers when the condition "u_non_standard_request_authorised" is set to true with an after and on insert and update. is the best solution.
Could someone assist with the actions I need to configure to update the group?
thanks
Craig
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2023 12:32 AM
Hi @Craig Nicholls
You can use Before BR - Insert & Update
with Condition u_non_standard_request_authorised is true
and in the script you can the following script
var gr = new GlideRecord('sys_user_grmember');
gr.initialize();
gr.group=current.assignment_group;
//field name or the object where group sys_id is stored on the form
gr.user = current.assigned_to;
//field name or the object where user sys_id is stored on the form.
gr.insert();
Hope this will work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2023 05:11 AM
Hi,
I think it can be achieved in different ways:
1) Writing the code in script include and calling the same in client script on change of the checkbox and is true create a record in sys_user_grmember table.
2) BR will work as well on the check box changes and is set to true condition and insert a record in sys_user_grmember table.
Thanks,
Hope this helps..!!
2)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2023 05:30 AM - edited 05-19-2023 05:32 AM
So create an After Business Rule against the Customer_Contact table. On the "When to Run" tab in the Filter Conditions section, add a condition for "Non Standard Request Authorized" is true (or changes to true).
Then on the Advanced tab you would add this script:
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', current.sys_id);
gr.addQuery('group', 'sys_id_of_group');//sys_id of Non-Standard Request Authorised
gr.query();
if(!gr.next())
{
gr.initialize();
gr.user = current.sys_id;
gr.group = 'sys_id_of_group';//sys_id of Non-Standard Request Authorised
gr.insert();
}
})(current, previous);
This will add the current user record on the Customer_Contact table to the group when that field changes to True. Assuming that record on the Customer_Contact table is a user in the system.
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven