How to check if user belongs to specific group in customized form?

I know how to do easily in a BPM, but how would I do this within a Form Customization?

So sorry found my answer here:

Just careful that code does not take in account the ~ and sometimes you could have 2 groups starting the same and it would mark as passed.

I defined a module based off of that post above taking a string of groups as to check against. Let me know if you think this will be a problem?

private bool bAuthedBypass(params string[] args)
	{
	if ( args != null ) 
		{
    	string userID = ((EpiDataView) this.oTrans.EpiDataViews["CallContextClientData"]).dataView[0]["CurrentUserId"].ToString();
		try
    		{
			UserFileAdapter adapterUserFile = new UserFileAdapter(this.oTrans);
			adapterUserFile.BOConnect();
			bool result = adapterUserFile.GetByID(userID); 
			if (result)
				{
				foreach (string uGroup in args) 
					{ 
					if (adapterUserFile.UserFileData.UserFile[0]["GroupList"].ToString().IndexOf(uGroup) != -1)
						{
						// MessageBox.Show("User belongs to " + uGroup + " Group");    
						return true; 
						}
					}
				}
        
	        adapterUserFile.Dispose();
	    	}
    	catch (System.Exception ex)
    		{
        	ExceptionBox.Show(ex);
	    	}
		}
	return false;
	}

Lets for a moment assume the user belongs to 3 groups

SALESADM~SALESADMMGR~SALESADMASSISTANT

If you look for “Sales Admin” (SALESADM) all 3 would return it exists. So I usually split it into a List and then check with .Contains

adapterRow[“GroupList”].ToString().Split(‘~’).ToList()

I have something similar to Jose

private bool Security(string groupID)
    {
        bool recSelected;
        Ice.Core.Session session = (Ice.Core.Session) oTrans.Session;
        bool belongs = false;
        string whereClause = "DcdUserID='"+session.UserID+"'";
        System.Data.DataSet dsUserFileAdapter = Ice.UI.FormFunctions.SearchFunctions.listLookup(this.oTrans, "UserFileAdapter", out recSelected, false, whereClause);
        if (recSelected)
        {
            System.Data.DataRow adapterRow = dsUserFileAdapter.Tables[0].Rows[0];
 
            // Check to see if User belongs to BRANCH User Group
             
                if(adapterRow["GroupList"].ToString().ToUpper().Contains(groupID.ToUpper()))
                {
                    belongs = true;
                }           
        }
        return belongs;
    }

And one can create a BAQ with a calculated field that does the same split logic. And if you can do it in a BAQ, you can do it in a BPM or Epicor Function.

A post was split to a new topic: Advice on how to prevent changes within the price break EpiUltraGrid on the Quote Form