
There are various ways in x++ to check the current company in X++ (Ax2012 / D365FO).
1. Using SysCountryRegionCode::isLegalEntityInCountryRegion
Simplest built-in method.
Example:
#ISOCountryRegionCodes
if (SysCountryRegionCode::isLegalEntityInCountryRegion(#isoUS))
{
info("Current legal entity is in the United States.");
}
Pros: Direct, readable, uses enum. No Hard-coding of the legal entity
Cons: Limited to predefined SysCountryRegionCode macro values.
2. Using CompanyInfo::current()
Retrieves the CompanyInfo recordId for the current DataAreaId.
Example:
CompanyInfo companyInfo = CompanyInfo::current();
if (companyInfo.CountryRegionId == 'US')
{
info("Legal entity is US");
}
This method is provided for callers which need the record ID of a legal entity but do not need any other fields.
Pros: Flexible, can check against any country code string.
Cons: Requires explicit string comparison.
3. Querying CompanyInfo Table
Direct query using curext() (current company ID).
Example:
CompanyInfo companyInfo;
select firstOnly companyInfo
where companyInfo.DataArea == curext();
if (companyInfo.CountryRegionId == 'GB')
{
info("Legal entity is UK.");
}
Pros: Useful if you need additional metadata (name, address, etc.).
Cons: Slightly heavier than CompanyInfo::current().
Original Post https://anithasantosh.wordpress.com/2025/11/20/different-ways-to-check-the-current-legal-entity-in-x/






