How to hide fields in DetailView in VtigerCRM

How to hide fields in DetailView in VtigerCRM

Often in the development process we are faced with the task of hiding certain fields depending on the value of the field. There are many modules on the market that implemented this feature without the need for programming, but they work in javascript. Those, the fields are hidden only after the page is fully loaded. This also causes some inconvenience to users and creates an additional load on the system.

Therefore, I decided to share a simple way to hide fields at the php level. Luckily, it's very easy and fast. All you need to do is create 1 new file and make small changes to two existing files.

For example, let's imagine such a task - we need to show a certain set of fields depending on the status of the deal at the moment.

First, let's create a configuration file where we will store an array of fields that we will allow to be displayed for the Deals module.

Let's create a vtiger_detailview_list.php file at the root with the following content



$detailview_list = array(

    'Potentials' => [

        'checkField' => 'cf_1269',

        'checkValue' => 'Submission Received',

        'allowedFields' => [

            'potentialname', 'potential_no', 'cf_1269', 'cf_3709', 'cf_3713', 'cf_3867', 'cf_4368', 'cf_3711', 'cf_4421', 'forecast_amount', 'cf_1926'





In order for the configuration array to be available as a global variable, you need to import this file into the configuration file

require_once 'vtiger_detailview_list.php';


What is a configuration array? This is a multidimensional array divided by modules. The key of the first level is the name of the module. In it, we describe which field we are checking in the checkField key (its system name) and its value in the checkValue key. Further in allowedFields we describe the list of fields that we allow to be shown.


The hiding itself takes place in the modules/Vtiger/models/DetailRecordStructure.php file.

Here we need to add a function:

    protected function isFieldAllowed(string $fieldName, ?Vtiger_Record_Model $record): bool


        global $detailview_list;

        if (!$record) {

            return true;


        if (!isset($detailview_list[$record->getModuleName()]['checkField'])) {

            return true;


        $fieldValue = $record->get($detailview_list[$record->getModuleName()]['checkField']);

        if ($fieldValue === $detailview_list[$record->getModuleName()]['checkValue']) {

            return in_array($fieldName, $detailview_list[$record->getModuleName()]['allowedFields'], true);


        return true;



Next, in the getStructure function, near line 39, rewrite the condition. Instead of






if($fieldModel->isViewableInDetailView() && $this->isFieldAllowed($fieldName, $recordModel))


And that's enough. Now if the transaction status is "Submission Received", then in the Detail View we will see only those fields that are registered in the array. Of course, this method does not protect us from displaying fields in edit mode or displaying them in a general list, but I hope the general approach is clear.

Popular Posts

My most popular posts

Maximum productivity on remote job

Maximum productivity on remote job

I started my own business and intentionally did my best to work from anywhere in the world. Sometimes I sit with my office with a large 27-inch monitor in my apartment in Cheboksary. Sometimes I’m in the office or in some cafe in another city.

Hello! I am Sergey Emelyanov and I am hardworker
Business PHP

Hello! I am Sergey Emelyanov and I am hardworker

I am a programmer. I am an entrepreneur in my heart. I started making money from the age of 11, in the harsh 90s, handing over glassware to a local store and exchanging it for sweets. I earned so much that was enough for various snacks.

Hire Professional CRM developer for $25 per hour

I will make time for your project. Knowledge of Vtiger CRM, SuiteCRM, Laravel, and Vue.js. I offer cooperation options that will help you take advantage of external experience, optimize costs and reduce risks. Full transparency of all stages of work and accounting for time costs. Pay only development working hours after accepting the task. Accept PayPal and Payoneer payment systems. How to hire professional developer? Just fill in the form