How do I hide the cell phone in the contacts

Hello again,
How do I hide the cell phone in the contacts and leads section for users and not for administrators, that is, in this way 95******41, im trying using roles but i can’t see that option specific

Thanks.

Hi,
You cannot do it via Roles, It can only be via custom coding.
Can you mention your SuiteCRM version?

Thanks for answering, the version of suitecrm I have is 8.4.2

A strategy to do this is to use a combination of
after_retrieve and before_save logic hooks

In the after_retrive logic hook you can hide the phone numbers.
In the before_save logic hook you can put the original phone numbers back in the fields because you don’t want them to be saved as **** in the database.
you can find original phone numbers in the $bean->fetched_row[‘phone_work’] variable

Put in conditions for only non admin users.

If you don’t want to code it yourself

Hello, I try as you said it this way in the folder.

suitecrm/public/legacy/custom/modules/Leads

I modified the file logic_hooks.php de la siguiente manera

<?php
 $hook_version = 1; 
$hook_array = Array(); 
$hook_array['before_save'] = Array(); 
$hook_array['before_save'][] = Array(1, 'Leads push feed', 'modules/Leads/SugarFeeds/LeadFeed.php','LeadFeed', 'pushFeed'); 
$hook_array['before_save'][] = Array(2, 'Hide/Restore Phone Numbers', 'custom/modules/Leads/HidePhoneNumberLogicHook.php', 'HidePhoneNumberLogicHook', 'hideRestorePhoneNumbers');

$hook_array['before_save'][] = Array(77, 'updateGeocodeInfo', 'modules/Leads/LeadsJjwg_MapsLogicHook.php','LeadsJjwg_MapsLogicHook', 'updateGeocodeInfo'); 
$hook_array['after_save'] = Array(); 
$hook_array['after_save'][] = Array(1, 'updateRelatedMeetingsGeocodeInfo', 'modules/Leads/LeadsJjwg_MapsLogicHook.php', 'LeadsJjwg_MapsLogicHook', 'updateRelatedMeetingsGeocodeInfo');

$hook_array['after_save'][] = Array(77, 'updateRelatedMeetingsGeocodeInfo', 'modules/Leads/LeadsJjwg_MapsLogicHook.php','LeadsJjwg_MapsLogicHook', 'updateRelatedMeetingsGeocodeInfo'); 

?>

Likewise, create the following file HidePhoneNumberLogicHook.php with the code

<?php

if (!defined('sugarEntry') || !sugarEntry) {
    die('Not A Valid Entry Point');
}

class HidePhoneNumberLogicHook
{
    public function hideRestorePhoneNumbers($bean, $event, $arguments)
    {
        global $current_user;

        if (!$current_user->isAdmin()) {
            if ($event == 'before_save') {
                $originalPhoneNumber = $bean->fetched_row['phone_work'];
                $bean->phone_work = $originalPhoneNumber;
            } elseif ($event == 'after_retrieve') {
                $bean->phone_work = 'PhoneHide';
            }
        }
    }
}
?>

I would love to buy your solution but I am only trying to develop specific things in a learning environmen

The plugin I posted is not my solution it’s just one of the many available in suitecrm store

In the logic_hooks.php you have added a before_save logic hook but not an after_retrive logic hook

Here’s the documentation on logic hooks

1 Like

Hi everyone, finally i was do it by myself like this.

In the folder.
suitecrm/public/legacy/custom/modules/Leads
modified the file logic_hooks.php that way

<?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(
    1, 
    'Leads push feed', 
    'modules/Leads/SugarFeeds/LeadFeed.php',
    'LeadFeed', 
    'pushFeed'
); 

$hook_array['before_save'][] = Array(
    77, 
    'updateGeocodeInfo', 
    'modules/Leads/LeadsJjwg_MapsLogicHook.php',
    'LeadsJjwg_MapsLogicHook', 
    'updateGeocodeInfo'
); 

$hook_array['after_save'] = Array(); 
$hook_array['after_save'][] = Array(
    77, 
    'updateRelatedMeetingsGeocodeInfo', 
    'modules/Leads/LeadsJjwg_MapsLogicHook.php',
    'LeadsJjwg_MapsLogicHook', 
    'updateRelatedMeetingsGeocodeInfo'
); 

$hook_array['after_retrieve'] = Array();
$hook_array['after_retrieve'][] = Array(
    1,
    'Hide Mobile Phone for Users',
    'custom/modules/Leads/HideMobilePhoneLogicHook.php',
    'HideMobilePhoneLogicHook',
    'hideMobilePhone'
);
?> 

Likewise, create the following file HidePhoneNumberLogicHook.php at the same folder with the code

<?php

if (!defined('sugarEntry') || !sugarEntry) {
    die('Not A Valid Entry Point');
}

class HideMobilePhoneLogicHook
{
    public function hideMobilePhone($bean, $event, $arguments)
    {
        
        global $current_user;

        // Verificar si el usuario actual no es un administrador
        if (!$current_user->is_admin) {
            $bean-> phone_mobile = 'Oculto';
            // Ocultar el número de teléfono móvil
        }
    }
}

?>

With that solution, if you open the record in Edit view, and then save it without changing the phone field, doesn’t the “Oculto” get saved in the DB, causing you to lose the data?

Users are only limited to viewing and cannot edit