Hide subpanel depend on roles

Hello all,
I want to hide some subpanel base on role.
Anyone know how can I achieve this?

Thanks

I am not sure it works, but if you disable the entire module in the Role (“access” column) doesn’t it remove subpanels?

Also try disabling “List views” since subpanels are derived from List views.

Tell me if this works! Thanks

HELLO PQR,
Thanks for reply.
I already tried this, but it’s not working.

I have solved this with custom code.
I have create custom file in custom\Extension\modules\Leads\Ext\Layoutdefs/custom_file.php
and add below code. After adding code perform a “Quick Repair and Rebuild”.
And it’s work for me.

global $mod_strings, $app_strings, $sugar_config;
$objACLRole = new ACLRole();
$roles = $objACLRole->getUserRoles($GLOBALS['current_user']->id);
if($roles[0] == "Call Center"){
		unset($layout_defs["Leads"]["subpanel_setup"]["campaigns"]);
		unset($layout_defs["Leads"]["subpanel_setup"]["securitygroups"]);
}

Thanks

1 Like

use javascript to hide subpanel :slight_smile:

1 Like

Hi pepemon2018,
Any problem if I write this in Layoutdefs?
I’m new in suitecrm.
Thanks :slight_smile:

just tested it with the current LTS-version. Created a group, added role+user, works exactly as you described (column access=disabled is sufficient).

Exception: for activities and history I’m unsure if the principle works.

Thanks @diligent

About the other discussion, doing it in Layoutdefs versus Javascript, I believe in this case the Layoutdefs is better:

  • it’s faster handling the request on the server, the subpanel query doesn’t run

-less bandwidth consumed, less page load time

  • no data will be sent to the front-end, so it’s more secure if you really don’t mean the data to be there

Thanks pgr :slight_smile:

you can create javascript tag in layoutdefs. (y)

1 Like

Thanks pepemon2018,
I’ll try js :slight_smile:

get Subpanel ID ! then use js :slight_smile:

1 Like

Why would you want to use Javascript for this case?

I gave several reasons above, saying why it’t not very adequate. it seems to me it’s also a much more convoluted form of achieving the intended purpose.

You can simply tell SuiteCRM not to produce the subpanel, by unsetting a value in a array. Why would you want to tell it to produce the subpanel anyway, send it to the client, but inject Javascript in it, so it can then be insecurely hidden?

1 Like

@jrawoot @pgr

I am looking to do a similar thing but I want to display/hide an Accounts subpanel based on the value of a variable in the Account record. In my case, if the account_type equals “Venue” then show the “Events Hosted” subpanel (a custom relationships I created).

I put the following into custom/Extension/module/Accounts/Ext/Layoutdefs/conditionallyHideSubpanel.php

<?php

if ( 1 ) {
    unset($layout_defs['Accounts']['subpanel_setup']['fp_events_accounts_1']);
}

That worked when I manually changed to 1 to a 0

So now my challenge is, how, when in custom/Extension/module/Accounts/Ext/Layoutdefs, can I identify the value in the variable of the record being displayed?

I do not know how to call the $bean->account_type variable, since, unlike a logic hook, I am not being given the $bean.

Do you know how to pull the $bean being displayed when in the Layoutdefs directory?

You can set a debugger breakpoint on that line and examine which variables are available; but I don’t think you’ll find what you need, I believe this code is executed earlier, just setting up all the view and layout defs, I don’t think it executes when you have a specific record loaded…

@pgr

Thank you
By looking at what variables are available, I now have it working

If you want a Layoutdefs method to show or hide a subpanel based on the value of a variable in the record, use

$this->_focus->variable_name

In my case, in the Accounts module, I wanted to show/hide an “Events Hosted” subpanel (custom relationship using link fp_events_accounts_1 in the subpanel layoutdefs to get subpanel data) based on the value of the account_type variable being “Venue” or not.

I added Venue=>Venue to the account_type dom.

To do this, put into custom/Extension/module/Accounts/Ext/Layoutdefs/conditionallyHideSubpanel.php

<?php

if ( $this->_focus->account_type != "Venue" ) {
    unset($layout_defs['Accounts']['subpanel_setup']['fp_events_accounts_1']);
}

Quick Repair and Rebuild

When you set the account_type to Venue, the “Events Hosted” subpanel is shown.

When you have the account_type set to something other than “Venue”, the “Events Hosted” subpanel is not shown.

Edit to suit your situation.

1 Like

Yes you can do it. Also you can do it with jquery. just like below.

if( $('#account_type').val() != "Venue" ){
    $('#whole_subpanel_activities').hide()
}
1 Like

@jrawoot
Thank you
I have not used jquery code before; I’ll have to look into that.

Hello
Could you tell me where to modify the JS?