After a few weeks of looking around, digging into example after example after example, I finally stumbled across a simple method to dynamically hide a panel on the Detail and Edit View in SugarCRM.
As you’re probably aware, SugarCRM has a ton of business logic hooks, whether for the application frame, the modules themselves, or the users–such as logging in, out, etc.
This example makes use of the ‘after_ui_frame’ application logic hook, which, in Sugar’s terminology, is “fired after the frame has been invoked and before the footer has been invoked.” In simpler English, the ‘after_ui_frame’ hook will run your class and method at the beginning of just about every page. So yes, this is where you would put custom javascript, such as in the event you wanted an alert window on every page.
But you can also put CSS in here! Here’s how I used the ‘after_ui_frame’ to hide a panel so that some users don’t see a specific panel on a specific module. Keep in mind this is only a superficial way of hiding the data and should only be used to simplify the layout. Data will still be visible by viewing the source code of the page.
Step 1
First, create a file called “logic_hooks.php” and place it in your custom/modules/ folder. Your logic_hooks.php file should look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 <?php //Hide Subpanels based on User Role written by Dean Haddock for StoryCorps (2012) if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); // Set the version hooks should use, currently Sugar only supports version 1. $hook_version = 1; // Initialize the hook array $hook_array = Array(); // Initialize the hook type $hook_array['after_ui_frame'] = Array(); $hook_array['after_ui_frame'][] = array( 1, //Hook version 'Hides panels depending on roles.', //Label 'custom/modules/hidepanels.php', //Include file 'HidePanelsClass', //Class 'HidePanelsMethod' //Method ); ?>
Step 2
Next, create a file called “hidepanels.php” and place it in the same directory as above. In this document, place the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 <?php // Hide Subpanels based on User Role written by Dean Haddock for StoryCorps (2012) class HidePanelsClass{ function HidePanelsMethod(&$bean, $event, $arguments) { // HIDE PANEL ON WEB CHANGE REQUEST MODULE // // if($_GET[module]=='<YOUR MODULE>' OR $_POST[module]=='<YOUR MODULE>') { // Because EditView and DetailView use POST and GET respectively. There are some additional cases you may need to modify, such as for the import view. In that case, just add to your IF statement something like, $_GET['action']=WHATEVER. global $current_user; // so you can see who your user is // include the roles code include("modules/ACLRoles/ACLRole.php"); $acl_role_obj = new ACLRole(); $user_roles = $acl_role_obj->getUserRoles($current_user->id); // get all the roles the user belongs to $show_role = "<PUT YOUR ROLE HERE>"; // choose the role who you want to SEE this panel, for example $user_in_role = (in_array($show_role,$user_roles) ? 1 : 0); // check to see if the user's role is in the array // $bean->fetched_row['status'] is the stored status of the case, $bean->status would be the new value /custom/themes/default/images if($user_in_role!=1) { // if the user isn't part of the role, then hide the panel echo '<style type="text/css"> #LBL_PANEL1 {display:none !important;}</style>'; // css to hide the panel } } // // // END HIDE PANEL } } ?>
That’s it! Of course, you can customize this to your liking. Perhaps you want to hide a panel from everyone unless they’re an admin, or maybe you want to hide financial information in an order fulfillment module. The only thing is–this method superficially hides the panel, but the content of the panel will still be visible if the user views the source.
Happy coding…

Have you taken a look at SugarLogic? This can be done via SugarLogic and it handles the issues with required fields for you. If the panel is hidden, the fields are not required.
Good Idea
Maybe you have forgot if some required field are in a hidden panel ??
You must think to remove the javascript validation ..
@Ezmou–That’s a very good point! I’ll amend the article to mention that. Thanks!!
Awesome post Dean. This is the kind of stuff that saves hours “Googling”. I really do appreciate a well written blog posting.
UPDATE:
If you wanted to hide a panel only on the detailView of a record, you would just add this to your IF statement:
&& $_GET['action']==”DetailView”