Tuesday, January 31, 2012

Get the Current Active Company in Dynamics AX.


Hi,

To get the Current Logged In Company you can Use the curExt() function in AX.

Example :

static void curExtExample(Args _arg)
{
str CompanyId;
;

CompanyId = curExt();
Info(CompanyId);
}



You would also get the same result with below code as well.

static void curExtExample(Args _arg)
{
str CompanyId;
;

CompanyId = CompanyInfo::Find().DataAreaId;
Info(CompanyId);
}


Enjoy DAX!!!

2 comments:

  1. Hello Kuldeep,

    CompanyId = CompanyInfo::Find().DataAreaId will return the first record in CompanyInfo table. Most likely it will be DAT company. So it shouldn't be used to return the current active company. CompanyId = curExt() should be used instead.

    Thank you for your helpful post!

    ReplyDelete
  2. CompanyInfo::Find() returns only from current Company as it does:

    select firstonly CompanyInfo
    where CompanyInfo.DataArea == curext();

    ReplyDelete

Thanks for your time reviewing this blog.