#1656 - Add a new user to security group via Logic Hook
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
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.
9 years ago
Many thanks for you swift reply. A sample code will be truly appreciated.
9 years ago
The key is to use the link name and not the relationship name for loading the relationship (a huge head scratcher):
Hope that helps!
9 years ago
Brilliant. Works link a charm.
Your help is truly appreciated.
9 years ago
Glad to help! Closing this out for now.