Hide related field depending on the value of a Dropdown List(or other logic)?

Hello I wanted to hide two fields depending on a dropdown value:

System: Sugar Enterprise 7.8

Scenario:

Module where I want to hide: moduleA

On record/create view there is a dropdown: docType (values: typeB, typeC, both, none)

There is two related modules: moduleB, moduleC

Logic (trying to write as a pseudo code):

If the docType=typeB

   hide moduleC related field;

Else if the docType=typeC

   hide module B related field;

Else if the docType=none

   hide both related field;

Else if the docType=both

   do nothing, dont hide the related field;

There is a solution trough the create.js and record.js but a little bit old, and not detailed: How to hide a field in preview? 

Tried something like that but not works.

*record.js

({     extendsFrom: 'RecordView',      initialize: function (options) {
     this._super('initialize', [options]);this.model.on('hide:related',_showHideFields);     },
    
     _showHideFields:function(model, collection, fetch) {
          var docType = this.model.get('docType_c');// fetches  docType dropdown value
          if(doc_type === "typeB")
          {                   
               $('div[name="MOD_moduleA_MOD_moduleC_1_name"]').parent().hide();
          }         
          else if(doc_type === "typeC")
          {
               $('div[name="MOD_moduleA_MOD_moduleB_1_name"]').parent().hide();
          }    
     },    
})

There is missing something?

The code just not works.

Thank You for Your suggestions!

Regards,

Arpad

Parents
  • Hi Arpad Szabo

                           Have you tried using the onchange event

    Regards

    Sidhu

  • Hello, 

    at the end we used another method. 

    Instead of hiding a specific related field we decided a much easier method: to hide whole panels.

    There is a method to use some Dependencies in modules. 

    For example, we wanted to hide a Panel with a specific related field on it.

    Gone to the folder "Dependencies": /var/www/html/custom/Extension/modules/Opportunities/Ext/Dependencies

    And uploaded a php file called: hidetabs_opportunities

    With the content of this:

       $dependencies['Opportunities']['project_trigger']=array(  // custom name of the dependecy: 'project_trigger' (this can be anything, just need to be unique in this file)
         'hooks' => array("edit","view"), 
            'trigger' => 'true', 
            'triggerFields' => array('sales_stage'),  // what field should this be triggered on 
            'onload' => true, 
            'actions' => array( 
                array( 
                    'name' => 'SetPanelVisibility',  // the action you want to run - here we hide a whole panel
                    'params' => array( 
                        'target' => 'LBL_RECORDVIEW_PANEL3',  // name of the panel, can be found in the vardefs. 
                        'value' => 'isInList($sales_stage,createList("3","4a","4b","Closed Won"))',  // the formula to run to determine if the panel should be hidden or not. 
                    ),             
                ),         
            ), 
            );

    And done, the Panel with the related field is hiding if the sales stage of the Opportunity is not on the list.

    Regards,

    Arpad

Reply
  • Hello, 

    at the end we used another method. 

    Instead of hiding a specific related field we decided a much easier method: to hide whole panels.

    There is a method to use some Dependencies in modules. 

    For example, we wanted to hide a Panel with a specific related field on it.

    Gone to the folder "Dependencies": /var/www/html/custom/Extension/modules/Opportunities/Ext/Dependencies

    And uploaded a php file called: hidetabs_opportunities

    With the content of this:

       $dependencies['Opportunities']['project_trigger']=array(  // custom name of the dependecy: 'project_trigger' (this can be anything, just need to be unique in this file)
         'hooks' => array("edit","view"), 
            'trigger' => 'true', 
            'triggerFields' => array('sales_stage'),  // what field should this be triggered on 
            'onload' => true, 
            'actions' => array( 
                array( 
                    'name' => 'SetPanelVisibility',  // the action you want to run - here we hide a whole panel
                    'params' => array( 
                        'target' => 'LBL_RECORDVIEW_PANEL3',  // name of the panel, can be found in the vardefs. 
                        'value' => 'isInList($sales_stage,createList("3","4a","4b","Closed Won"))',  // the formula to run to determine if the panel should be hidden or not. 
                    ),             
                ),         
            ), 
            );

    And done, the Panel with the related field is hiding if the sales stage of the Opportunity is not on the list.

    Regards,

    Arpad

Children
No Data