How to Customize SugarCRM to Hide a Subpanel While Changing the Record Attribute

How to Customize SugarCRM to Hide a Subpanel While Changing the Record AttributeAuthor: Pavel Chumachenko, Software Engineer

We are repeatedly talking about the flexibility of SugarCRM system for various modifications.

This time we will discuss SugarCRM customization for the implementation of the mechanism that hides or displays the subpanel on the detail view card of the record with a specific value of its attribute.

Conditions

The best way to show such SugarCRM customization is to demonstrate it through the example. So, let’s say, we have a Company. Each of the Companies in the system is characterized by a Category. “Investor” is one of the possible values of this attribute. Also, each company has 2 sub-panels: “Investors” and “Investment Recipients” The task is to display “Investment Recipients” sub-panel when [Company.Category] = “Investor”, and display “Investors” sub-panel with another value of attribute Category. In other words, for any value of [Company.Category] we need to hide one of the sub-panels: either «Investors» or «Investment Recipients»

Below you may find a description of the standard connection of 2 sub-panels to the application block of the Company.

Path:

Code:

Where px_investors_link is a link indicating all the investors of the Company;

px_investment_recipients_link is a link indicating all the companies receiving investments from the company in question.

Reinventing the Wheel

The functional part of the system responsible for the display of sub-panels is described in subpanels.js controller.

Path:

To correct its operation in the module of the Company, we will be working in this file. Unless you have such a file, you should create it.

The first step is to indicate that we are inheriting from “SubpanelsLayout” and call a parent initialization method.

Code:

At the next step, let’s extend our class with properties needed to solve the main problem: “Do we have to hide the subpanel?”. We will specify at once that the sub-panel to be hidden / displayed, will be determined by its link title.

New properties of the class:

  • hide_subpanels is an array of subpanel records that can be hidden
  • check_field is the name of the parent record attribute, the value of which affects the display of the sub-panel(s)
  • check_field_value is the value of the attribute of the parent record specified in the previous property
  • hide_on_value is an object that consists of property-value pairs, where
    • property is the name of the subpanel link
    • value is an array of values ​​where the subpanel will be hidden

Code:

The preparatory work for our SugarCRM customization is done, so we can proceed to the main step – overriding of showSubpanel() method, which is responsible for displaying or hiding subpanels. In addition, we want to say that this is the only method to be overridden for the implementation of the current task. So, we need to change slightly the operation logic of showSubpanel() method. Namely, before calling show() method we need to add a new test: “Should the current subpanel be displayed?” If it turns out that the subpanel has to be hidden, call hide() method instead of show() method.

Code:

To check if the subpanel is available during the implementation of showSubpanel() method, _checkIfHideSubpanel() method shall be employed. It assumes one argument – subpanel, i.e. the name of the link of the current subpanel. It returns TRUE, if the sub-panel is in hide_subpanels array, and if the value of the checked attribute of the parent record is in the property of hide_on_value[subpanel] object. Otherwise, _checkIfHideSubpanel() method returns FALSE.

Code:

Conclusions

This article discussed how to customize SugarCRM for the implementation of the mechanism imposing additional restrictions on the display of the subpanel, depending on the value of the attribute of its parent record.

As usual, feel free to contact us if you need advice on how to customize SugarCRM to make it more convenient and efficient for your needs.

Other instructions on SugarCRM customization:

Leave a Reply

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