Using organizationSettings in Model-Driven Apps: Context-Aware UX for the Win

As Power Platform developers, we often write logic that needs to behave differently depending on which environment or organization our code is running in.

Whether it’s toggling features for internal teams vs partners, showing localized content, or adapting functionality based on supported currencies Xrm.Utility.getGlobalContext().organizationSettings gives you the data you need to make smarter UI decisions.

Let’s dive into what it gives you, and how to use it effectively in real-world scenarios.


🧠 What is organizationSettings?

Xrm.Utility.getGlobalContext().organizationSettings returns metadata about the Dataverse environment (organization) where your model-driven app is running.

It provides details such as:

  • baseCurrencyId and baseCurrencyCode
  • languageId and languageCode
  • uniqueName of the environment
  • isUserAccessModeReadOnly
  • organizationId
  • organizationName
  • useSkypeProtocol (legacy)

📘 Docs reference


🧪 Scenario 1: Environment-Specific UI Behavior

Let’s say you want to disable certain form fields or hide tabs in sandbox/test environments to avoid confusion or accidental changes.

function onLoad_toggleFieldsBasedOnEnvironment(executionContext) {
    const formContext = executionContext.getFormContext();
    const orgSettings = Xrm.Utility.getGlobalContext().organizationSettings;

    // Use uniqueName or organizationId to distinguish environments
    const isTestEnv = orgSettings.uniqueName.includes("test");

    if (isTestEnv) {
        formContext.getControl("new_sensitivefield").setVisible(false);
        formContext.ui.tabs.get("details").setVisible(false);
    }
}

🌍 Scenario 2: Show Localized Instructions Based on Organization Language

You may want to dynamically show instructions or help text based on the organization’s configured language.

function setLocalizedInstructions(executionContext) {
    const formContext = executionContext.getFormContext();
    const languageId = Xrm.Utility.getGlobalContext().organizationSettings.languageId;

    const instructionsField = formContext.getAttribute("new_instructions");

    switch (languageId) {
        case 1033: // English
            instructionsField.setValue("Please ensure all fields are complete.");
            break;
        case 1036: // French
            instructionsField.setValue("Veuillez remplir tous les champs.");
            break;
        case 1041: // Japanese
            instructionsField.setValue("すべてのフィールドに入力してください。");
            break;
    }
}

💱 Scenario 3: Show/Format Currency Fields Based on Base Currency

Let’s say your business logic depends on the organization’s base currency, and you want to highlight currency mismatches on a form.

function validateCurrencyAgainstBase(executionContext) {
    const formContext = executionContext.getFormContext();
    const baseCurrencyId = Xrm.Utility.getGlobalContext().organizationSettings.baseCurrencyId;
    const transactionCurrencyId = formContext.getAttribute("transactioncurrencyid").getValue();

    if (transactionCurrencyId && transactionCurrencyId[0].id !== baseCurrencyId) {
        formContext.getControl("amount").setNotification(
            "Warning: Transaction currency differs from the base currency."
        );
    }
}

The organizationSettings API is an underused gem in the Xrm toolbox. It gives you lightweight, contextual information about the Dataverse org, perfect for smart UI logic, ALM-friendly design, and localized experiences.

So the next time you’re wondering “How do I make this feature environment-aware?”—you know exactly where to look.

Leave a comment