Different ways to check the current legal entity in x++

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/

0 Votes: 0 Upvotes, 0 Downvotes (0 Points)

Leave a reply

Join Us
  • X Network2.1K
  • LinkedIn3.8k
  • Bluesky0.5K
Support The Site
Events
November 2025
MTWTFSS
      1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
« Oct   Dec »
Follow
Search
Popular Now
Loading

Signing-in 3 seconds...

Signing-up 3 seconds...