Reputation: 1295
I'm trying to obtain the role of some user (by its id), currently i do this way:
$this is a home-made API access outside of SugarCRM, the session is implicitly sent
$roles = $this->get_entry_list('ACLRoles', null, null, null, array('name'));
if ($roles) {
foreach ($roles->entry_list as $role) {
$result = $this->get_relationships('ACLRoles', $role->id, 'users', 'user_id=' . $userId);
if (count($result->entry_list) > 0) {
return array(
'id' => $role->id,
'name' => $role->name_value_list->name->value
);
}
}
}
I, however, consider this an inefficient solution, due that i need to iterate over all the roles to check if the user is there... I have been looking at the API and been trying other methods, but i cannot get to relation Users -> ACLRoles, only ACLRoles -> Users...
Is there a better way to get the Role of an User?
Upvotes: 0
Views: 1703
Reputation: 316
I'm using get_relationships in Sugar 6.5.8 to retrieve the roles for a given user via the SOAP service.
get_relationships(sessionId, "Users", userId, "aclroles", "", array("id", "name"))
Note: the link_field_name (4th) parameter appears to be case-sensitive, but doesn't error if you get it wrong like the module_name parameter... it is just ignored and no records returned.
Upvotes: 0
Reputation: 2208
Another option is to add a new web services call via your own custom endpoint. This is actually quite simple to do, see this KB article for more details...
Upvotes: 1