Skip to main content

Assign a same Security Groups of User A to User B (User Security Customization)

If you got a request to assign the same security groups of user A to user B, you will check the security groups for user A and then add them one by one to the user B and this will consume your time and the human error happens especially if you have a big list of groups . 

I will show you how to customize the User Security Maintenance and add this feature and you will fulfill the request in seconds.

To add this feature I have applied the below:
- Add EpiUltraCombo in group tab.
- Use sample search to fill this drop down list.
- Use custom dialog serach to get the groups list of the selected user.
- Using the save tool in the toolbar to assign the group list to the current user.
- Clear the text of the EpiUltraCombo when a user clicks on clear tool.



Here it’s the code:
The code has been tested in Epicor 9.05.604 version.

using System;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using System.ComponentModel;
using Epicor.Mfg.UI;
using Epicor.Mfg.UI.FrameWork;
using Epicor.Mfg.UI.ExtendedProps;
using Epicor.Mfg.UI.FormFunctions;
using Epicor.Mfg.UI.Customization;
using Epicor.Mfg.UI.Adapters;
using Epicor.Mfg.UI.Searches;
using Epicor.Mfg.BO;


public static class Script
{

    public static void InitializeCustomCode()
    {

        baseToolbarsManager.ToolClick += new Infragistics.Win.UltraWinToolbars.ToolClickEventHandler(baseToolbarsManager_ToolClick);
     
    }

    public static void DestroyCustomCode()
    {

        baseToolbarsManager.ToolClick -= new Infragistics.Win.UltraWinToolbars.ToolClickEventHandler(baseToolbarsManager_ToolClick);

    }

    private static void SearchOnUserFileAdapterFillDropDown()
    {

        bool recSelected;
        string whereClause = String.Empty;

        System.Data.DataSet dsUserFileAdapter = Epicor.Mfg.UI.FormFunctions.SearchFunctions.listLookup(oTrans, "UserFileAdapter", out recSelected, false, whereClause);
        if (recSelected)
        {
            // Set EpiUltraCombo Properties
            UCUser.ValueMember = "DcdUserID";
            UCUser.DataSource = dsUserFileAdapter;
            UCUser.DisplayMember = "Name";
            string[] fields = new string[] {
                                  "Name"};
            UCUser.SetColumnFilter(fields);
        }
    }


    private static void UserAccountForm_Load(object sender, EventArgs args)
    {
        // Add Event Handler Code
        SearchOnUserFileAdapterFillDropDown();
        UCUser.DropDownStyle = Infragistics.Win.UltraWinGrid.UltraComboStyle.DropDownList;
    }


    private static string SearchOnUserFileAdapterShowDialog(string sameAsUser)
    {

        // Wizard Generated Search Method
        // You will need to call this method from another method in custom code
        // For example, [Form]_Load or [Button]_Click
        string grpList = string.Empty;
        bool recSelected;
        string whereClause = " DcdUserID = '" + sameAsUser + "'";

        System.Data.DataSet dsUserFileAdapter = Epicor.Mfg.UI.FormFunctions.SearchFunctions.listLookup(oTrans, "UserFileAdapter", out recSelected, false, whereClause);
        if (recSelected)
        {
            // Map Search Fields to Application Fields
            grpList = (string)dsUserFileAdapter.Tables[0].Rows[0]["GroupList"];
        }
        return grpList;
    }


    private static void baseToolbarsManager_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs args)
    {
        if ((UCUser.Value != null) && (UCUser.Value.ToString() != ""))
        {
            EpiDataView userDV = (EpiDataView)oTrans.EpiDataViews["User"];
            DataRow currRow = userDV.CurrentDataRow;
            if (currRow != null)
            {
                if (args.Tool.Key == "SaveTool")
                {
                    currRow["GroupList"] = SearchOnUserFileAdapterShowDialog(UCUser.Value.ToString());
                }
            }
            if (args.Tool.Key == "ClearTool")
                UCUser.Text = "";
        }
    }

}



Comments

Popular posts from this blog

Epicor 9 ToolBars

Like any other application, Epicor has list of toolbars and it uses the Infragistics controls and you can modify these toolbars in your code by adding new tools or change the properties for the existing toolbars and Tools.

How to Use the Business Activity Query Export Process

Business Activity Query Export Process let you export the BAQ data in XML or CSV format. You can export the BAQ data manually and you can schedule it to run automatically (Daily, Weekly, ,Monthly,Once,startup..etc) and you can configure this in the “system agent maintenance” and I will explain this later in this article.