sugarcrm: show fields based on user

If you want to change the who is able to see for example the Assigned to Contacts on the Advanced Menus, because maybe you don't want employees to see names of all other users, you have to do an Edit Module by Module.

For example, lets say you have the Assigned to Menu on the Advanced Search of the Leads Module. Everybody with access to the Leads Module will be able to see this Menu which contains all of the users names. If you want only selected users to see it you can do the following:

Go to the following path.


This is basically an Array, so you'll want to add a Conditional to the field of the Array you want to add. Adding conditionals on an Array may by tricky. This is the format:

($Condition) ? (IF TRUE) : (IF FALSE)

So I will do something like: If the username is Admin (which username is 1) print the field otherwise return NULL

($user_id == "1") ? (Print Array) : NULL

See Below:

'assigned_user_id' => ($user_id == "1") ?
array (
'name' => 'assigned_user_id',
'type' => 'enum',
'label' => 'LBL_ASSIGNED_TO',
'function' =>
array (
'name' => 'get_user_array',
'params' =>
array (
0 => false,
'default' => true,
'width' => '10%',
) : NULL,


Now, to get the user ID you have to add before the Array Starts

global $current_user;
$user_id = $current_user->id;

That way the problem is resolved.


Support Information

global $current_user;
$user_id = $current_user->id;
echo $user_id ;


How to Print Smarty Variables!





Code to Get Field Shown or Not Shown

global $current_user;
$user_id = $current_user->id;

{if ( $user == 1)}

<td scope="row" nowrap="nowrap" width='8.3333333333333%' >

<label for='assigned_user_id_advanced'>{sugar_translate label='LBL_ASSIGNED_TO' module='A26_Proveedor'}</label>
<td nowrap="nowrap" width='25%'>

{html_options name='assigned_user_id_advanced[]' options=$fields.assigned_user_id_advanced.options size="6" style="width: 150px" multiple="1" selected=$fields.assigned_user_id_advanced.value}


Where to Add the Codes.



This Cache Files are Deleted when you Delete Cache, I believe that the PHP Files will have to be edited.


Leave a Reply

Your email address will not be published. Required fields are marked *