Here is my code- Same as the andopes gives.
logic hook-
PHP Code:
<?php
// Do not store anything in this file that is not part of the array or the hook version. This file will
// be automatically rebuilt in the future.
$hook_version = 1;
$hook_array = Array();
// position, file, function
$hook_array['before_save'] = Array();
$hook_array['before_save'][] = Array(2, 'addInProfile', 'custom/modules/Users/UserLogicHook.php','UserLogicHook', 'addInProfile');
?>
UserLogicHook.php
PHP Code:
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class UserLogicHook {
function addInProfile(&$focus, $event, $arguments) {
$role_name = "test100";
$query = "SELECT id FROM users WHERE id = '{$focus->id}'";
$result = $focus->db->query($query, true);
if($focus->db->getRowCount($result) == 0) {
$query = "SELECT id FROM acl_roles WHERE name = '$role_name'";
$result = $focus->db->query($query, true);
if($focus->db->getRowCount($result) == 1) {
$row = $focus->db->fetchByAssoc($result);
$focus->load_relationship('aclroles');
$focus->aclroles->add($row['id']); //this line gives error
$bean->new_with_id=true;
require_once('modules/ACL/install_actions.php');
} else {
sugar_die("Role test100 does not exist! Contact the system administrator");
}
}
}
}
?>
This solution works fine on other version. I tries it on sugar 6. I think I am having problem In my code or some relation ship issue because in role management the users list is not displayed.it may have some relationship issue!!
Reply soon please
Regards,
Pravin
Bookmarks