Hiding Panel based on Account value

I’m trying to hide a panel from Account DetailView depending on the Account Status (custom field).

I’ve been searching arround and I’ve found two ways of doing it, one is using de DevToolKit and the other one by edit the /custom/modules/accounts/views/view.detail.php

The first option didn’t work, and I’m triying with the second, by now I have:



	function display(){
				
		if(empty($this->bean->id)){
			global $app_strings;
			sugar_die($app_strings['ERROR_NO_RECORD']);
		}

		if($this->bean->estat_c =='POT'){
			echo('This is working');
			  unset($this->dv->defs['panels']['lbl_detailview_panel3']);
		}

...

The message “This is working” works, but I see the panel. Also tryied in UpperCase and other panel names (lbl_account_information).

I saw in other pots from sugarcrm that this is posible.

Thanks in advance,

instead of unsetting, try this:

print "<pre>";
print_r($this->dv->defs['panels']);
print "/<pre>";

Then analyse the array and unset the desired item of the array.

I used this, before and after unsetting.

Before unsetting I can see the panel in the array and afer unsetting I can’t see in

 but the panel is showing anyway.

	if($this->bean->estat_c =='POT'){
			print "<pre>";
			print_r($this->dv->defs['panels']);
			print "/<pre>";

			unset($this->dv->defs['panels']['lbl_detailview_panel3']);

			print "<pre>";
			print_r($this->dv->defs['panels']);
			print "/<pre>";

		}

Thanks

Finally I’ve fonud a solution after a long research:

  • Every time I edit the view-detail file, I make a quick repair and then the page is catched and is showing the panel on the first condition occurs on the client, but for all clients, so if the firts condition was ‘POT’ then all Accounts panels will be printing the same panels as ‘POT’ even they aren’t ‘POT’.

The only way I’ve found to avoid this is to enable develop mode before the function:



$GLOBALS['sugar_config']['developerMode'] = true;

and then it works.

I think this isn’t the cleanest way to do it. If anyone find a better way to do it it would be great to share it.

Hi there,

Developer mode can be enabled in Admin -> System Settings.

Thanks,

Will.

Here’s another way using Javascript in your custom ViewDetail

public function display(){
	$js= '';
	if (your condition to hide panel) {
		//JS to hide the panel
       		$js = <<<EOQ
			<script>
      			// Theme Suite7 & SuiteR
       			$("#detailpanel_2").addClass('hidden');
			// Theme SuiteP
			$("a[href=#top-panel-0]").parents('.panel-default').addClass('hidden');
			// Hide the tab - common to all themes
			$("a#tab1").parent().addClass('hidden');
       			</script>
EOQ;
		}
	parent::display();
	echo $js;     //echo the script.
}

Please can anyone tell me where should i found this viewdetail.php file i can’t find it anywhere.

So I’m trying to follow this thread (I’m a noob at this stuff) I gather I need to:

  1. create a custom view.detail.php file in /custom/modules/my_module/view.detail.php
  2. In my case if Line of Business is HVAC I want to hide the 3rd tab, id=“tab2”
  3. I have to extend ViewDetail and then use the above JS to hide the tab by changing the class to “hidden”
    Am I understanding it correctly or is it more complicated? (I can’t seem to get it to work)
            <?php


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

            require_once("include/MVC/View/views/view.detail.php");

        class bldg_Other_OppsViewDetail extends ViewDetail
        {

        if($this->bean->line_of_business_c =='HVAC'){

            public function display(){
        		$js= '';
        	
        		//JS to hide the panel
               		$js = <<<EOQ
        			<script type="text/javascript">
        					// Theme Suite7 & SuiteR
               			$("#detailpanel_2").addClass('hidden');
        			// Theme SuiteP
        			$("a[href=#top-panel-0]").parents('.panel-default').addClass('hidden');
        			// Hide the tab - common to all themes
        			$("a#tab2").parent().addClass('hidden');
               			</script>
        EOQ;
        		
        	parent::display();
        	echo $js;     //echo the script.
        		
        		
        	}
        }
        }

I think you are on the right path. Now you need to find the right object from javascript.

I’m using js to hide panel. It is working good with Suie7 until update. When i use SuiteP theme, it doesn’t work. What is wrong? Let me know please.

require_once('include/MVC/View/views/view.detail.php');

class ContactsViewDetail extends ViewDetail {

	function display() {

    	$role_to_check ="CIAD Comitee"; 

		$user_in_group = FALSE;  
		
		global $current_user;
		global $db;
		
		$getusergroup="select s.securitygroup_id as id from securitygroups_users s where s.deleted=0 and s.user_id='".$current_user->id."'
		and s.securitygroup_id in ('ae3d24dc-734d-4c21-149f-4c5035f8b5f8','d357b5ce-1c66-899d-03c9-4c6e20adcd36','8ad4e0e8-8eb4-d10a-a611-4c034f1c5e06')";
    
    	$resgetusergroup=$db->query($getusergroup, true);
		
		if($db->getRowCount($resgetusergroup)>0) {
    		$user_in_group = TRUE; 
		}		
		
	    $getuserindss="select s.securitygroup_id as id from securitygroups_users s where s.deleted=0 and s.user_id='".$current_user->id."' and s.securitygroup_id in ('8ad4e0e8-8eb4-d10a-a611-4c034f1c5e06')";
		$resgetuserindss=$db->query($getuserindss, true);
		if($db->getRowCount($resgetuserindss)>0) {
    		$user_in_dss = TRUE; 
		}	
		
		if (!$user_in_group){
            echo "<script>$(document).ready(function(){ $('#LBL_PANEL100').hide();";
			echo "$('#whole_subpanel_contacts_ahis_academichist').hide();";
			echo "$('#whole_subpanel_contacts_ahis_advisors').hide();});</script>";
			unset($this->dv->defs['templateMeta']['form']['panels']['lbl_panel100']); 

			$this->th2 = new TemplateHandler(); 
			$this->th2->clearCache($this->module); 
		}	
		
	
		if (!$user_in_dss){
            echo "<script>$(document).ready(function(){ $('#LBL_PANEL101').hide();$('#LBL_PANEL2').hide();});</script>";
			unset($this->dv->defs['templateMeta']['form']['panels']['lbl_panel101']); 
			unset($this->dv->defs['templateMeta']['form']['panels']['lbl_panel2']);
			$this->th2 = new TemplateHandler(); 
			$this->th2->clearCache($this->module); 
		}			

		$this->dv->process();
	
		echo $this->dv->display();
	}
	function process() {
  echo '<script src="custom/javascript/jquery/external/jquery/jquery.js" type="text/javascript"></script>';
  print '<style type="text/css">#create_link, #create_image{ display:none; }</style>';
        parent::process();
		}
}

@nelem

I know this post was 5 years ago, but I am working with SuiteCRM v7 and am trying to do what your solution allows, so hopefully you are still available to exchange ideas.

I used your solution and it works fine for my detailview - using both panels and tabs - with the following code

<?php

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

require_once('modules/Accounts/views/view.detail.php');

class CustomAccountsViewDetail extends AccountsViewDetail {

	public function display() {

        // Hide the Venue Information panel if the account_type is not Venue
        // Note the use of the editview panel definition 'lbl_editview_panel1'
        // which is used since we are synchronizing editview to detailview

		if ( $this->bean->account_type != "Venue" ) {
            //JavaSscript to hide the panel
            $jScriptToHidePanel = '';
            // Note that as of phpv7.3 the heredoc contents can be indented
            // including the end-of-heredoc line
            // Two caveats:
            //    - the contents of the heredoc must be indented
            //        at least as much as the end-of-heredoc line
            //    - the indentation can be either tab or space
            //        but NOT a combination of both
            $jScriptToHidePanel = <<<EndOfScript
            <script type="text/javascript">
                // Hide the panel
                // Theme SuiteP
                // Note the difference in the href between editviewdef and detailviewdef
                $("a[href=#top-panel-1]").parents('.panel-default').addClass('hidden');
                // Hide the tab - common to all themes
                $("a#tab2").parent().addClass('hidden');
            </script>
            EndOfScript;
		}
        parent::display();
        echo $jScriptToHidePanel;

	}
}

However, when I try to do the same for the editview, it does work when I use tabs, but not when I use panels. I did change the id to match the panel description for editview instead of detailview, but it does not help


<?php

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

require_once('modules/Accounts/views/view.edit.php');

class CustomAccountsViewEdit extends AccountsViewEdit {

	public function display() {

        // Hide the Venue Information panel if the account_type is not Venue
		if ( $this->bean->account_type != "Venue" ) {
            //JavaSscript to hide the panel
            $jScriptToHidePanel = '';
            // Note that as of phpv7.3 the heredoc contents can be indented
            // including the end-of-heredoc line
            // Two caveats:
            //    - the contents of the heredoc must be indented
            //        at least as much as the end-of-heredoc line
            //    - the indentation can be either tab or space
            //        but NOT a combination of both
            $jScriptToHidePanel = <<<EndOfScript
            <script type="text/javascript">
                // Hide the panel
                // Theme SuiteP
                // Note the difference in the href between editviewdef and detailviewdef
                $("a[href=#detailpanel_1]").parents('.panel-default').addClass('hidden');
                // Hide the tab - common to all themes
                $("a#tab2").parent().addClass('hidden');
            </script>
            EndOfScript;
		}
        parent::display();
        echo $jScriptToHidePanel;

	}
}

Do you have any suggestions for how to make this work for the Edit View when using Panels?

So I have it working on edit view perfectly with the code below. My problem is that when I create a new account, it hides the panel because obviously the record is not created yet and “lead_account_type_dom_c” will always not be equal to lender.

I’ve tried AND isset() and !=Null, I just can’t see the right condition for my IF statement to show the tab when it’s a new record and the field is blank, or not populated. Anyone point me in the right direction.

<?php

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

require_once('modules/Accounts/metadata/editviewdefs.php');

class CustomAccountsViewEdit extends ViewEdit {

	public function display() {

        // Hide the Venue Information panel if the account_type is not Venue
    $value=  $this->bean->lead_account_type_dom_c;
		if ( $value !="Lender" ) {
            //JavaSscript to hide the panel
            $jScriptToHidePanel = '';
            // Note that as of phpv7.3 the heredoc contents can be indented
            // including the end-of-heredoc line
            // Two caveats:
            //    - the contents of the heredoc must be indented
            //        at least as much as the end-of-heredoc line
            //    - the indentation can be either tab or space
            //        but NOT a combination of both
            $jScriptToHidePanel = <<<EndOfScript
            <script type="text/javascript">
                // Hide the panel
                // Theme SuiteP
                // Note the difference in the href between editviewdef and detailviewdef
                $("a[href=#detailpanel_1]").parents('.panel-default').addClass('hidden');
                // Hide the tab - common to all themes
                $("a#tab1").parent().addClass('hidden');
            </script>
            EndOfScript;
		}
        parent::display();
        echo $jScriptToHidePanel;

	}
}

Maybe check if the id field of the bean is set, or not.

1 Like

Thanks @pgr your the best!!! You’ve helped me out tons over the years. Huge thank you. That totally worked!!!

So basically in edit view, a new record shows the tab, since what “type” of account isn’t established yet, and if you are editing an existing record, it works properly and hides the tab when it meets the conditions. Working code is below if anyone else needs it:

<?php

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

require_once('modules/Accounts/metadata/editviewdefs.php');

class CustomAccountsViewEdit extends ViewEdit {

	public function display() {

        // Hide the Venue Information panel if the account_type is not Venue
    $value=  $this->bean->lead_account_type_dom_c;
    $id = $this->bean->id;
		if ( $value !="Lender" and isset($id)) {
            //JavaSscript to hide the panel
            $jScriptToHidePanel = '';
            // Note that as of phpv7.3 the heredoc contents can be indented
            // including the end-of-heredoc line
            // Two caveats:
            //    - the contents of the heredoc must be indented
            //        at least as much as the end-of-heredoc line
            //    - the indentation can be either tab or space
            //        but NOT a combination of both
            $jScriptToHidePanel = <<<EndOfScript
            <script type="text/javascript">
                // Hide the panel
                // Theme SuiteP
                // Note the difference in the href between editviewdef and detailviewdef
                $("a[href=#detailpanel_1]").parents('.panel-default').addClass('hidden');
                // Hide the tab - common to all themes
                $("a#tab1").parent().addClass('hidden');
            </script>
            EndOfScript;
		}
        parent::display();
        echo $jScriptToHidePanel;

	}
}
2 Likes

Hello @pstevens , are you hidings tab panel? I am trying to hide my panel also but its not working on edit view.
image

I add the Javascript thru Custom.tlp check my codes below

<script>
    {literal}
    //Account Type
    var radioChange = "input[name='customer_classification_c']";
    YAHOO.util.Event.onDOMReady(function () {
        disabledCustomerClassType();

        YAHOO.util.Event.addListener(YAHOO.util.Selector.query(radioChange), "change", function () {
            disabledCustomerClassType();
        });

        function disabledCustomerClassType() {
            if ($('input[name="customer_classification_c"]:checked').val() == 'Commercial') {
                $('#customer_classification_type').attr('disabled',false);
                $('#customer_classification_type').val('SME');
                $('#name').attr('disabled',false);

                $('#personal_information').val('');
                $('#contact_id_c').val('');
                $('#first_name').val('');
                $('#middle_name').val('');
                $('#last_name').val('');
                $('a[href=#detailpanel_0]').parents('.panel-default').addClass('hidden');
            } else {
                $('#customer_classification_type').val('');
                $('#customer_classification_type').attr('disabled',true);
                $('#name').attr('disabled',true);

                $('#first_name').attr('readonly',true);
                $('#middle_name').attr('readonly',true);
                $('#last_name').attr('readonly',true);
                $('a[href=#detailpanel_0]').parents('.panel-default').removeClass('hidden');
            }
        }
    });
{/literal}
</script>

I was able to fix it. check my code below:

$('div[id="detailpanel_0"]').parents('.panel-default').addClass('hidden');
1 Like