by eggsurplus

Control what your users can access and save time, money, and frustrations. Lock down sensitive data in SuiteCRM to specific groups or teams. Supports unlimited assigned users, unlimited group assignments to records, custom layouts for each group, login/sudo capabilities and much more.

Cancel at any time!
Free Trial

Developer Tips

How do I add a group to a record when a field value changes?

Add a before_save logic hook that checks for the field value change. Upon change load the SecurityGroups relationship and add the "id" of the group that you wish to add to the record.

The example below detects when the account type dropdown changes on an account. When it gets changed to "Customer" a "Support Group" gets assigned to the account.

/custom/modules/Accounts/ReassignSecurityGroup.php:

class ReassignSecurityGroup {

    function account_type_change(&$bean, $event, $arguments)
    {   
        //detect if Type dropdown has been changed to Customer
        if($bean->account_type != $bean->fetched_row['account_type'] && $bean->account_type == 'Customer') {
            $bean->load_relationship('SecurityGroups'); //use the link name...can find in cache/modules/{MODULE}/{MODULE}vardefs.php
            $bean->SecurityGroups->add('cd1cf3bb-9eb3-4b24-b488-529b908fed70'); //add Support Group to the record
        }
    }
}

And the /custom/modules/Accounts/logic_hooks.php:

$hook_version = 1; 
$hook_array = Array(); 
$hook_array['before_save'] = Array(); 
$hook_array['before_save'][] = Array(1, 'account_type_change', 'custom/modules/Accounts/ReassignSecurityGroup.php','ReassignSecurityGroup', 'account_type_change'); 

How do I add a group to a newly created user?

The easiest way to do this is to go to SecuritySuite Settings and in the "Default Groups for New Records" section at the bottom choose Users for the module and then which group you want assigned to it.

Sometimes you'll want finer control though. To do that add a before_save hook on the Users module and then add the group that you want based on your logic to the user.

if(empty($bean->id) || $bean->new_with_id == true)
{
    $default_group = BeanFactory::getBean('SecurityGroups');
    $default_group->retrieve_by_string_fields(array('name'=>'Owner_Only_Group','deleted'=>0));
    $default_group->load_relationship('users');
    $default_group->users->add($bean->id);
}
  1. johnby member avatar

    johnby

    5 years ago

    Good afternoon.
    Question.
    How do I add a group to the recording inside editviewdefs (documents, aos_quotes, contackts or other record) ???
    I added a Relatefield (SecurityGroups) to the choice of the group.
    I got the name of the group and id.
    Now I need to add or change the group from recording through editviewdefs!
    Use need logic_hooks.

    • eggsurplus member avatar

      eggsurplus Provider Affiliate

      5 years ago

      Are you wanting to be able to assign groups at the time of record creation on the edit view? If you use the Use Creator Group Select option then it will automatically appear if a user is a member of 2 or more groups.

Saving Comment Saving Comment...
Rating
  • "The add-on itself was already a must for my SuiteCRM, which was missing this very important security feature. However, what surprised me the most was ..." - Davint

    Read More Reviews