by eggsurplus

Control what your users can access and save time, money, and frustrations. Lock down sensitive data in SugarCRM or 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.

Free 30 day trial
Try it Now

By clicking you consent to share your profile with the developer

#1656 - Add a new user to security group via Logic Hook

Closed General Question created by EliasJ 9 years ago

I am trying to automatically add new users to a security group via a logic hook every time a new user is created. Below is what I have managed to put together myself but it just doesn't seem to work.

$sgroupx = new SecurityGroup(); $sgroupx->retrieve_by_string_fields(array('name'=>'Owner_Only_Group','deleted'=>0)); $sgroupx->load_relationship('securitygroups_users'); $sgroupx->securitygroups_users->add($bean->id);

Any advice or sample code that you may have to help will be appreciated, Cheers

  1. eggsurplus member avatar

    eggsurplus Provider Affiliate

    9 years ago

    Hi Elias,

    I'll come back with a code example, but another way of going about this is to go to Security Suite Settings and at the bottom set up a default group for the Users module so that any newly created User gets assigned to the Owner Only Group in the "Default Groups for New Records" section.

  2. EliasJ member avatar

    EliasJ

    9 years ago

    Many thanks for you swift reply. A sample code will be truly appreciated.

  3. eggsurplus member avatar

    eggsurplus Provider Affiliate

    9 years ago

    The key is to use the link name and not the relationship name for loading the relationship (a huge head scratcher):

                $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);
    

    Hope that helps!

  4. EliasJ member avatar

    EliasJ

    9 years ago

    Brilliant. Works link a charm.

    Your help is truly appreciated.

    • eggsurplus member avatar

      eggsurplus Provider Affiliate

      9 years ago

      Glad to help! Closing this out for now.

This case is public. Please leave out any sensitive information such as URLs, passwords, etc.
Saving Comment Saving Comment...
Rating
Rating
  • "Good product, but we need to support 'Quick Create' feature. and raised up this request to your page." - lcyang

    Read More Reviews