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 Trial

By clicking you consent to share your profile with the developer

#234 - can't add securitygroup relationship to account using add()

Closed Bug? created by rodnikosh Verified Purchase 11 years ago

i'm using 643_Basic_SecuritySuite_252 version on 6.4.3 sugarcrm version.

in the Account before_save logichook, i have the code to add the account to the group. i want to add a relationship between teh account and the group. but i get a blank screen in the row with the Add() function: This code works for every relation between other modules and account. only for relating securitygroup ot the account it fails. (selecting a group for the account using the subpanel works as normal):

$securityTeam = new SecurityGroup(); $securityTeam->retrieve_by_string_fields(array('name' => $field_securityGroup )); if ( $securityTeam->id == null) { $GLOBALS['log']->fatal("Group with the name '" . $field_securityGroup . "' wasn't found!"); continue; }

$securityTeam->load_relationship('accounts'); $securityTeam->accounts->add($bean->id); /// falis here - blank screen
$bean->save();

  1. rodnikosh member avatar

    rodnikosh Verified Purchase

    11 years ago

    also $secGroups = $bean->get_linked_beans('securitygroups_accounts','SecurityGroup'); returns empty array although Securtygroups are added in the subpanel of this account.

    its like the relationship in the code is gone while in the detailview it exist.

    this code works for other modules, only this relationship returns nothing.

    • eggsurplus member avatar

      eggsurplus Provider Affiliate

      11 years ago

      I'm not sure how it could even work for any other module. There isn't a link defined in the SecurityGroups module to any other module because it needs to support unlimited, unknown modules at the time of install. Basically, it needs to be flipped by going at it from the Account bean, loading the relationship to Security Groups, and adding the group to the account bean. The link in the Accounts module to Security Groups is "SecurityGroups". The relationship is "securitygroups_accounts". And if this doesn't work there is always the option to directly insert into the db. Although that isn't always ideal.

      Hope that helps! Thanks for being so supportive over the SecuritySuite over the years, rodnikosh!

    • rodnikosh member avatar

      rodnikosh Verified Purchase

      11 years ago

      Thank you for the great support eggsurplus. you also helped me alot in the sugarcrm forum over the years.

      when i said the code works with other modules , i meant that the code works for retrieving and adding new relationship between accounts and leads or accounts and opportunities, not that the security group works with other modules. i just meant that the code works, but not when trying to relate a module recrd to securitygroup.

      i already tried going the other way, so i defined a new accounts_securitygroups (not securitygroups_account), many-to-many relationship and used the code above from the account side. it created another subpanel of securitygroups as expected. and the code passed succesfully. but as soon as i gave my employee team a role of "group" level in "list" role column of account module, when my employee logged in, he saw in the account listview, records that are not in his group and the ones that are, weren't there. i checked and rechecked the group, the user access roles and and roles, it just didn't work. it only works with the original many-to-many relationship "account_securitygroups" when i select the record from the subpanel, but i need to do that from the code. i'll try to turn on "display_errors" in the php.ini, maybe i will get an error message in the blank screen....

      i really want it to work because this is a great module.

    • eggsurplus member avatar

      eggsurplus Provider Affiliate

      11 years ago

      Always glad to help! If you are using the Basic edition check out this document on how to manually hook up other modules that aren't stock: http://www.sugarforge.org/frs/download.php/6477/SecuritySuite_Documentation_2.1.pdf

      The key is that the relationship must be defined correctly and a link vardef must be defined on the side that you want to add from. Then reference the link when doing the load_relationship and add() calls. It does work for this, it may just take a few attempts to get right.

  2. rodnikosh member avatar

    rodnikosh Verified Purchase

    11 years ago

    yep , works like a charm :)

    $securityTeam = new SecurityGroup(); $securityTeam->retrieve_by_string_fields(array('name' => $field_securityGroup )); if ( $securityTeam->id == null) { $GLOBALS['log']->fatal("Group with the name '" . $field_securityGroup . "' wasn't found!"); continue; }

    $bean->load_relationship('SecurityGroups'); $bean->SecurityGroups->add($securityTeam->id); $bean->save();

    replaced it to work from the account (bean) side and also learned for the first time that the "link" is a field in the vardefs that i supposed to take its 'name' property , not the full relationship name (not "securitygroups_account" but "SecurityGroups").

    thank you for the great support.

  3. rodnikosh member avatar

    rodnikosh Verified Purchase

    11 years ago

    also getting linked beans after i took the name of the 'link' in the vardefs:

    $secGroups = $bean->get_linked_beans('SecurityGroups','SecurityGroup');

This case is public. Please leave out any sensitive information such as URLs, passwords, etc.
Saving Comment Saving Comment...
Rating
Rating
  • "Very responsive development team, both in their communication and in having improvements incorporated and issues resolved." - kevin

    Read More Reviews