Order Entry: Hide Sales Rep Panel if not a member of a User Group

My apologies, that is is fairly simple from a customization perspective, but while I’ve messed with Epicor and light customization’s for 10 years, I’m getting in deeper and I’m lost.
The Objective: To hide the Sales Order Entry header & Line Sales Rep panels when the current user does not belong to a certain user group. We recently put a few BPMs in place that determines the Sales Rep Commission Rate, but we don’t want the order entry person or a few other to see these values.

I really thought is would be pretty easy, so from past experience and some posts here I have got the following to compile, which only attempts to hide the panel:

    		Erp.UI.App.SalesOrderEntry.HedSalesPersonPanel SalesPersonPanel = (Erp.UI.App.SalesOrderEntry.HedSalesPersonPanel)csm.GetNativeControlReference("4fef8b01-7269-47eb-bee9-f8b637e8d7ce");
		    SalesPersonPanel.Visible = false;

However, it does’t work, no error, the panel just doesn’t hide.
I can hide it ‘manually’ with the control property, but that wouldn’t be dynamic per the user’s user group.

My next hurdle will be figuring out if the user belongs to the allowed user groups and to control the visibility.

Since we have a BPM in place that is setting values on the panel I didn’t think disabling the panel would work, but I thought this might.

If anyone has already done this and willing to share your code, that would make this easier.

Thanks!

Rick,

I’ve been able to do this on some forms, not on others. Over the years, I’ve found that you can often copy/paste sample code from one form to another and it doesn’t work - always figured it was some issue in Epicor. Anyway, if hiding the tabs doesn’t work, you can always hide the group boxes on the tab. It’s a blank tab, doesn’t look as pretty as hiding the tab - but does the job.

Kevin Simon
SimsTrak Consulting, LLC

Could you remove the tab from the parent control’s collection?

When are you triggering this code? Form load event?

Yes the Load Event.

I’ve never done that before, much less know how.

Thanks @SimsTrak, that’s Plan B.
When I run into something I can’t do, I get hung up on it.
Elegance would be nice, I hate to settle.

This customization hides the panel on form load.App.SalesOrderEntry.SalesOrderForm_Customization_HidePanel_CustomExport.xml (6.5 KB)

1 Like

You’ve probably already considered this, but one other option would be to create two different customizations (one with the desired content hidden and one displayed). Then put them both on the menu with different security group settings depending on which customization it is. I’m assuming a majority of future changes on either of these customizations would have to be duplicated on the other though to keep them both up to date on what they’re supposed to do.

App.SalesOrderEntry.SalesOrderForm_Customization_SO_Entry_V01_CustomExport.xml (12.3 KB)

Please find attached or below code User Group base Security for Commission tab Header and line level.

private void SalesOrderForm_Load(object sender, EventArgs args)
{
	// Add Event Handler Code
	HideSalesPersonPanel();
}

private void HideSalesPersonPanel()
{
	Ice.Core.Session userSession = (Ice.Core.Session)oTrans.Session; 
	if (!GetUserByID(userSession.UserID))
    {            
		Erp.UI.App.SalesOrderEntry.HedSalesPersonPanel salesPersonPanel = ((Erp.UI.App.SalesOrderEntry.HedSalesPersonPanel)csm.GetNativeControlReference("4fef8b01-7269-47eb-bee9-f8b637e8d7ce"));
		Erp.UI.App.SalesOrderEntry.LineCommissionsPanel lineCommissionsPanel = ((Erp.UI.App.SalesOrderEntry.LineCommissionsPanel)csm.GetNativeControlReference("6c823cb2-baf8-4d50-bbb1-052848f578a7"));
		salesPersonPanel.Visible = false;
		lineCommissionsPanel.Visible = false;
    }
}

private bool GetUserByID(string dcdUserID)
{
    bool isUserAccess = false;
    try
    {
        UserFileAdapter adapterUserFile = new UserFileAdapter(this.oTrans);
        adapterUserFile.BOConnect();
        bool result = adapterUserFile.GetByID(dcdUserID);
        if (result)
        {
            Erp.BO.UserFileDataSet.UserFileDataTable userDataTable = adapterUserFile.UserFileData.UserFile;
            if (Convert.ToBoolean(userDataTable.Rows[0]["SecurityMgr"]) || Convert.ToString(userDataTable.Rows[0]["GroupList"]).Contains("OFCMGR"))//Replace your User Group Code here
                isUserAccess = true;
        }
        adapterUserFile.Dispose();
    }
    catch (System.Exception ex)
    {
        ExceptionBox.Show(ex);
    }
    return isUserAccess;
}

note :- user File adapter dll references.

3 Likes

@Rick_Bird above code fulfilled your needs?

Sorry, I didn’t have a chance to test it out til now.
Thanks for this, it will work nicely. Still kinda wish it was possible to hide the tab.
Thanks again everyone!!!

1 Like

@Rick_Bird, @josecgomez Sorry I’ve been out of city for delay in reply. following are the code to hide tab based on user group security hope this will fulfill your requirement .

private void SalesOrderForm_Load(object sender, EventArgs args)
{
	// Add Event Handler Code
	HideSalesPersonPanel();
}

private void HideSalesPersonPanel()
{
	Ice.Core.Session userSession = (Ice.Core.Session)oTrans.Session; 
	if (!GetUserByID(userSession.UserID))
    {            
		Erp.UI.App.SalesOrderEntry.HedSalesPersonPanel sp_Panel = ((Erp.UI.App.SalesOrderEntry.HedSalesPersonPanel)csm.GetNativeControlReference("4fef8b01-7269-47eb-bee9-f8b637e8d7ce"));
		Infragistics.Win.UltraWinDock.DockableWindow sp_PanelDockWindow = (Infragistics.Win.UltraWinDock.DockableWindow)sp_Panel.Parent;
		Infragistics.Win.UltraWinDock.DockableControlPane sp_PanelDockPane = (Infragistics.Win.UltraWinDock.DockableControlPane)sp_PanelDockWindow.Pane;
		sp_PanelDockPane.Close();
		Erp.UI.App.SalesOrderEntry.LineCommissionsPanel lineCommPanel = ((Erp.UI.App.SalesOrderEntry.LineCommissionsPanel)csm.GetNativeControlReference("6c823cb2-baf8-4d50-bbb1-052848f578a7"));
		Infragistics.Win.UltraWinDock.DockableWindow lineCommPanelDockWindow = (Infragistics.Win.UltraWinDock.DockableWindow)lineCommPanel.Parent;
		Infragistics.Win.UltraWinDock.DockableControlPane lineCommPanelDockPane = (Infragistics.Win.UltraWinDock.DockableControlPane)lineCommPanelDockWindow.Pane;
		lineCommPanelDockPane.Close();
    }
}

private bool GetUserByID(string dcdUserID)
{
    bool isUserAccess = false;
    try
    {
        UserFileAdapter adapterUserFile = new UserFileAdapter(this.oTrans);
        adapterUserFile.BOConnect();
        bool result = adapterUserFile.GetByID(dcdUserID);
        if (result)
        {
            Erp.BO.UserFileDataSet.UserFileDataTable userDataTable = adapterUserFile.UserFileData.UserFile;
            if (Convert.ToBoolean(userDataTable.Rows[0]["SecurityMgr"]) || Convert.ToString(userDataTable.Rows[0]["GroupList"]).Contains("OFCMGR"))//Replace your User Group Code here
                isUserAccess = true;
        }
        adapterUserFile.Dispose();
    }
    catch (System.Exception ex)
    {
        ExceptionBox.Show(ex);
    }
    return isUserAccess;
}
1 Like

Thanks @surendrapal this was even better.
I had to change it a bit to accommodate checking for multiple Security Groups:

\\had to add LINQ to do this elegantly.
using System.Linq;

private bool GetUserByID(string dcdUserID)
{
    bool isUserAccess = false;
	string SecGrps = "SalesMgr, AcctMgr, HR";
    try
    {
        UserFileAdapter adapterUserFile = new UserFileAdapter(this.oTrans);
        adapterUserFile.BOConnect();
        bool result = adapterUserFile.GetByID(dcdUserID);
        if (result)
        {
            Erp.BO.UserFileDataSet.UserFileDataTable userDataTable = adapterUserFile.UserFileData.UserFile;
            if (Convert.ToBoolean(userDataTable.Rows[0]["SecurityMgr"]) || SecGrps.Any(Convert.ToString(userDataTable.Rows[0]["GroupList"]).Contains))
				isUserAccess = true;
        }
        adapterUserFile.Dispose();
    }
    catch (System.Exception ex)
    {
        ExceptionBox.Show(ex);
    }
    return isUserAccess;
}
2 Likes

Were you ever able to get the tab hidden? I am running into the same problem.

Yes, I marked @surendrapal latest reply the best answer and I posted my modified code to check for multiple security groups instead of just one as the last post.

Hello E10 Folks…

We wanted to take a stab at creating a BAQDataView on PartEntry. We were successful at getting this done on a custom panel. We then wanted to continue this and see if we could hide/show the added panel based on User Security Group membership. Utilizing the code posted here has been a great outline. I think we don’t have a firm grasp on the assembly references. When we compile we get the following:

Compiling Custom Code …

----------errors and warnings------------

Error: CS0234 - line 95 (444) - The type or namespace name ‘SupplierPriceList’ does not exist in the namespace ‘Erp.UI.App.PartEntry’ (are you missing an assembly reference?)
Error: CS0234 - line 95 (444) - The type or namespace name ‘SupplierPriceList’ does not exist in the namespace ‘Erp.UI.App.PartEntry’ (are you missing an assembly reference?)
Error: CS0234 - line 114 (463) - The type or namespace name ‘UserFileDataSet’ does not exist in the namespace ‘Erp.BO’ (are you missing an assembly reference?)

** Compile Failed. **

SupplierPriceList is the name of our custom panel and we thought that was needed.
As for the UserFileDataSet, I am unsure of what is reference (or using) I should add.
Outside of the Native Assemblies, we added:
Ice.Adapters.UserFile
Ice.Contracts.BO.Userfile

Any help our guidance is much appreciated.

// **************************************************
// Custom code for PartForm
// Created: 4/22/2019 3:13:08 PM
// **************************************************

extern alias Erp_Contracts_BO_Part;
extern alias Erp_Contracts_BO_PartPlantSearch;
extern alias Erp_Contracts_BO_PO;
extern alias Erp_Contracts_BO_PartOnHandWhse;
extern alias Erp_Contracts_BO_Vendor;
extern alias Erp_Contracts_BO_VendorPPSearch;
extern alias Ice_Contracts_BO_UserFile;

using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Erp.Adapters; 
using Erp.UI;
using Ice.Lib;
using Ice.Adapters;
using Ice.Lib.Customization;
using Ice.Lib.ExtendedProps;
using Ice.Lib.Framework;
using Ice.Lib.Searches;
using Ice.UI.FormFunctions;
using Ice.Lib.Broadcast;



public class Script
{
	// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables'     
Comments! **
	// Begin Wizard Added Module Level Variables **

	// End Wizard Added Module Level Variables **

// Add Custom Module Level Variables Here **
BAQDataView baqViewSupplierPriceList;


public void InitializeCustomCode()
{
	// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
	// Begin Wizard Added Variable Initialization

	// End Wizard Added Variable Initialization

	// Begin Wizard Added Custom Method Calls

	// End Wizard Added Custom Method Calls
	CreateSupplierPriceListBAQView();
}

public void CreateSupplierPriceListBAQView()

{
	baqViewSupplierPriceList = new BAQDataView("SupplierPriceList");
	oTrans.Add("SupplierPriceListBAQ",baqViewSupplierPriceList);

	
	string pubBinding = "Part.PartNum";
	IPublisher pub = oTrans.GetPublisher(pubBinding);
			
	baqViewSupplierPriceList.SubscribeToPublisher(pub.PublishName, "VendPart_PartNum");
	
}

public void DestroyCustomCode()
{
	// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
	// Begin Wizard Added Object Disposal

	// End Wizard Added Object Disposal

	// Begin Custom Code Disposal

	// End Custom Code Disposal
}

private void PartForm_Load(object sender, EventArgs args)
{
	// Add Event Handler Code
	HideSupplierPriceListPanel();		
	
}

private void HideSupplierPriceListPanel()
{
	
	Ice.Core.Session userSession = (Ice.Core.Session)oTrans.Session; 
	if (!GetUserByID(userSession.UserID))
{            
		Erp.UI.App.PartEntry.SupplierPriceList sp_Panel = ((Erp.UI.App.PartEntry.SupplierPriceList)csm.GetNativeControlReference("f7952705-e201-472f-8da3-f33228bc6075"));
		Infragistics.Win.UltraWinDock.DockableWindow sp_PanelDockWindow = (Infragistics.Win.UltraWinDock.DockableWindow)sp_Panel.Parent;
		Infragistics.Win.UltraWinDock.DockableControlPane sp_PanelDockPane = (Infragistics.Win.UltraWinDock.DockableControlPane)sp_PanelDockWindow.Pane;
		sp_PanelDockPane.Close();
			
 }

}

private bool GetUserByID(string dcdUserID)
{
    bool isUserAccess = false;
    try
    {
        UserFileAdapter adapterUserFile = new UserFileAdapter(this.oTrans);
        adapterUserFile.BOConnect();
        bool result = adapterUserFile.GetByID(dcdUserID);
        if (result)
        {
            Erp.BO.UserFileDataSet.UserFileDataTable userDataTable = adapterUserFile.UserFileData.UserFile;
            if (Convert.ToBoolean(userDataTable.Rows[0]["SecurityMgr"]) || Convert.ToString(userDataTable.Rows[0]["GroupList"]).Contains("_Purchasing"))//Replace your User Group Code here
                isUserAccess = true;
        }
        adapterUserFile.Dispose();
    }
    catch (System.Exception ex)
    {
        ExceptionBox.Show(ex);
    }
    return isUserAccess;
}

}

Any luck for this same requirements with kinetic UI using App Studio?