2
votes

I want to HIDE the Sales Order Line Commissions Tab, but I only want the Tab Hidden for a Specific Role. Is this possible?

1

1 Answers

2
votes

Option #1: Using PXTabItem VisibleExp property

This approach works perfectly with fairly simple declarative conditions, which utilize input control values from a particular container (PXForm is most commonly used for this scenario).

For example, to hide the Sales Order Commissions tab for orders of the TR type, you should compose VisibleExp as follows:

<px:PXTabItem Text="Commissions"
              VisibleExp="DataControls[&quot;edOrderType&quot;].Value!=TR" 
              BindingContext="form" 
              RepaintOnDemand="false">

A quick overview of the 3 PXTabItem properties used in the code snippet above:

  • BindingContext: the ID of the container control hosting input controls used to calculate visible property for PXTabItem
  • VisibleExp: the expression to calculate visible property for PXTabItem
  • RepaintOnDemand: controls the initialization of PXTab control. When set to True (the default value) PXTabItem will be initialized only when a user selects the Tab, otherwise, it will initialize with every postback.

Option #2: In code hide all controls placed inside PXTabItem

Without a doubt, this approach is a step forward in terms of flexibility comparing to PXTabItem VisibleExp property. It allows you to compose way more complex conditions inside business logic and do not rely on a webpage.

To hide the Sales Order Commissions tab, you should subscribe to the RowSelected handler for SOOrder as follows:

public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry>
{
    public void SOOrder_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
    {
        SOOrder order = (SOOrder)e.Row;
        if (order == null) return;

        bool financeRoleMember = System.Web.Security.Roles.IsUserInRole("FINANCE");
        Base.SalesPerTran.AllowSelect = financeRoleMember;
        PXUIFieldAttribute.SetVisible<SOOrder.salesPersonID>(Base.Document.Cache, null, financeRoleMember);
    }
}

With AllowSelect property set to false, the SalesPerTran data view will automatically hide every PXGrid, whose DataMember property is set to SalesPerTran. Since the Sales Order Commissions tab also contains Default Salesperson lookup, we need to additionally set Visible property to false for the PXUIFieldAttribute decorating SOOrder SalesPersonID field. PXTabItem automatically hides when it contains no visible controls.

Please be advised, similar to PXTabItem VisibleExp property, in order for this approach to function properly, you have to always set RepaintOnDemand to false for the PXTabItem you conditionally hide. For this particular example, we can skip this step, because RepaintOnDemand is set to false in the original SO301000.aspx file distributed by Acumatica.