How to use logged in company data into code

As a Dynamics 365 Finance & Operations (D365FO) Technical Consultant, one of the common requirements is to fetch details of the current legal entity (company).

Here’s a small but powerful X++ line that helps us:

CompanyInfo companyInfo = CompanyInfo::findRecId(CompanyInfo::current());


👉 CompanyInfo

A standard table in D365FO.

Stores company-specific details like Name, Address, Currency, Tax info, Contact details etc.


👉 CompanyInfo::current()

Returns the RecId of the company you are currently logged into.

Example: If you are in USMF, it gives the RecId of USMF.


👉 CompanyInfo::findRecId(...)

Finds and returns the full CompanyInfo record for the given RecId.


✅ Together, they give you all the details of the logged-in company.


Example:

CompanyInfo companyInfo = CompanyInfo::findRecId(CompanyInfo::current());


info(strFmt("You are logged into company: %1", companyInfo.Name));

info(strFmt("Default currency: %1", companyInfo.CurrencyCode));


🌟 Why is this useful?

No need to hardcode company information.

Your code automatically adapts to the logged-in company.

Super handy in multi-company environments (which is very common in D365FO).


🚀 Key Takeaways:

CompanyInfo::current() → gets current company’s RecId.

CompanyInfo::findRecId(...) → fetches the full company record.

A must-know snippet for any D365FO Technical Consultant.


👨‍💻 I use this often in reports, integrations, and business logic to ensure my code is company-aware.


Comments

Popular posts from this blog

JSON-Based HTTP POST Request from X++ to Retrieve an Access Token

Calling an External API from D365FO Using X++ to Retrieve a Token

Restricting Date Selection in Dynamics 365 FO using X++