Get Current Company Name

Hi All,

Want to give you a short trick – how to extract company name from the currently logged in user:

Company Name


Here we have 2 things:

  • PXSessionContext (PXContext.PXIdentity) – System class that stores environment variables in session like User, TimeZone, Branch, Locale. Actually this is used for user authentication authorization. However user here is stored with a full notation – like “user@company:branch”. But we can cut a part of it using special rules.
  • PXLogin – set of tools that can help to login user and use username. In our case it can extract company name right from full identity name.

Company ID


Here we have an PXInstanceHelper class that helps to get some environment variables, like currently logged in company, site folder, IIS version, Database Name, IP Address.

Hope it helps!

9 Replies to “Get Current Company Name”

  1. Hi Sergey,

    I’m trying to add custom field which will be defaulted to the current CompanyKey value
    I can get company name using [PXDefault(typeof(AccessInfo.companyName))] but I need company key

    Can you advise on this?

      1. Method #1 doesn’t work if result of PX.Common.PXContext.PXIdentity.IdentityName is just user name. In my tests it was just “admin” without company name. Is there more reliable way? Thank you

        1. Mykhaylo, please note that if there is only One company, that username is displayed without company.
          In case of multiple companies, than user name will have a company name in the end.

          1. Sergey, thanks for clarifications. But how to get name of current company in case of One company?! It’s a legal case, right?! Please would you suggest?

            1. Mykhaylo, could you please give me the reason and scenario why you need company name, I’ll help you with the best approach.

              1. Sergey,

                You want too much 🙂 What do you think about this solution:

                string companyName = PX.Data.PXLogin.ExtractCompany(PX.Common.PXContext.PXIdentity.IdentityName);
                if (string.IsNullOrEmpty(companyName))
                var key = PX.Data.Update.PXInstanceHelper.CurrentCompany;
                UPCompany item = null;

                foreach (UPCompany info in PXCompanyHelper.SelectCompanies())
                if (info.CompanyID == key)
                item = info;
                if (item != null)
                companyName = item.LoginName;

                At least it worked for me.

                Thank you,
                Mykhaylo Makarkin

            2. “Base.Accessinfo.CompanyName” and “item.LoginName” will give you the different result. That is why I’m asking
              LoginName – is the company name how it is displayed on login page
              CompanyName – is how company that is currently selected in the business logic. Like branch.
              If you want to login to Acumatica. You have to use LoginName how it is described here.

Leave a Reply

Your email address will not be published. Required fields are marked *