#573 - Assign Records
Hello,
I'm trying to add a functionality to SugarCRM using the Securty Suite. I want to add automatically the teams when i create a case, and for that, this support page was very helpful as i used part of the code that i saw in another post:
$securityTeam = new SecurityGroup(); $securityTeam->retrieve_by_string_fields(array('name' => $field_securityGroup ));
$bean->load_relationship('SecurityGroups'); $bean->SecurityGroups->add($securityTeam->id); $bean->save();
The problem is that i don't know the name of the team, i just know the id of the user that belongs to the teams i want to add. I know that i can do this with a query to the securitygroups_users table, but i want to do this without doing queries to provide a better performance.
There are another way i can do this?
Thanks in advance for your help!
Regards,
Joana Lopes da Fonseca
9 years ago
Which teams do you want to automatically add? If you want those that are related to the user SecuritySuite already does that out of the box. With the Inherit from Created By or Inherit from Assigned User it will grab all teams for that user and associate it to any newly created case.
If you want a specific team to always be added to any newly created Case you can even set default teams for each module on the SecuritySuite Settings page.
To your question about grabbing teams for a user, there is a function in SecurityGroup.php called getUserSecurityGroups(). Just pass the user ID and you'll get all teams for that user.
Hope that helps! -Jason
9 years ago
I know you've figured this out, but for anyone else who runs into it and who doesn't want to have to use code to do it you can now assign groups automatically when you create or edit a record (plus many other scenarios) using Process Manager. Here is a tutorial on how to do that: https://www.sugaroutfitters.com/docs/securitysuite/process-manager-adding-groups
-Jason