Try to display different panels based on users' roles

Hi everyone,

I try to display different panels in my custom module’s detail view based on users’ roles.
Here is my code for view.detail.php


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


class a1234_meViewDetail extends ViewDetail
    function a1234_meViewDetail()
    function display()
    	if(empty($this->bean->id)) {             
 			global $app_strings;             

    	if(file_exists('cache/modules/' . $this->bean->module_dir . '/DetailView.tpl'))             unlink('cache/modules/' . $this->bean->module_dir . '/DetailView.tpl');  

    	global $current_user;
    	foreach($toggle_panel_fieldsdefs as $role => $field_defs){
 			foreach($field_defs as $field => $visible){
 				if ($current_user->check_role_membership($role)){
 					foreach($this->dv->defs['panels'] as $panel => $panel_defs){                 
 						if ((strtoupper($panel) == strtoupper($field)) && ($visible == 0)) {
 							//$this->dv->defs['panels'][$panel] = array();

However, there is a problem.
After I login as one role, the code works well, for example, a sale panel is hidden.
I switch to another role which the sale panel should be displayed.
Nevertheless, the sale panel is still hidden from that user.

Once a panel is unset, it never come back until repair the system.
Can anybody help me?

Do you just the need the panel hidden in the browser (but present in HTML source), just for practical effect, or do you need it completely removed from HTML (for security reasons)?

have you tried to hide it with javascript?

Just want to hide it in browser.

Hi mikebeck,

I know I could hide it with javascript, but that would be more complex, and not easy to maintain. I just want to figure out how to realize it with my method.

Maybe you can search for clues here


there are functions like set_hidden_subpanels and get_hidden_subpanels which seem to manipulate settings to hide subpanels. This is probably what the app saves in “Admin / Display modules and Subpanels” option.