Making Your App Smarter with userSettings: Context-Aware UI in Dynamics 365

When building model-driven apps, one of the most powerful (and underutilized) ways to enhance the user experience is by adapting behavior based on the current user’s settings.

That’s exactly what Xrm.Utility.getGlobalContext().userSettings allows you to do, access contextual details about the user, their preferences, and security privileges at runtime.

In this post, we’ll explore:

  • What’s available via userSettings
  • Real-world use cases for customizing your forms and logic
  • Code examples that solve actual business problems

🔍 What Is userSettings?

The userSettings object exposes key information about the currently logged-in user:

const userSettings = Xrm.Utility.getGlobalContext().userSettings;

It includes metadata like:

  • User ID and name
  • Roles and privileges
  • UI preferences (RTL, contrast mode)
  • Base currency
  • Default dashboard
  • Date/time formatting
  • Language preferences
  • Time zone offset

🧪 Real-Life Scenarios and Code Examples


🧠 Scenario 1: Customize UI for Right-to-Left Languages

If your app supports Arabic or Hebrew, you may want to adjust labels, spacing, or tooltips accordingly.

function adjustForRTL(executionContext) {
    const isRTL = Xrm.Utility.getGlobalContext().userSettings.isRTL;

    if (isRTL) {
        // Change a label or layout for RTL languages
        const formContext = executionContext.getFormContext();
        formContext.getControl("description").setLabel("الوصف");
    }
}

👓 Scenario 2: Adjust Styles for High Contrast Mode

This helps support users with accessibility needs.

function checkHighContrastMode() {
    if (Xrm.Utility.getGlobalContext().userSettings.isHighContrastEnabled) {
        console.log("High contrast is enabled. Adjust styling accordingly.");
        // You could dynamically inject CSS or modify tooltips
    }
}

📊 Scenario 3: Highlight Currency Mismatch

Check the user’s preferred currency against a form’s transaction currency field.

function validateCurrency(executionContext) {
    const formContext = executionContext.getFormContext();
    const userCurrency = Xrm.Utility.getGlobalContext().userSettings.transactionCurrency;

    const txnCurrency = formContext.getAttribute("transactioncurrencyid").getValue();
    if (txnCurrency && txnCurrency[0].id !== userCurrency.id) {
        formContext.getControl("amount").setNotification(
            `Note: You're entering data in ${txnCurrency[0].name}, but your profile currency is ${userCurrency.name}.`
        );
    }
}

🌐 Scenario 4: Adjust Date Formats Dynamically

Leverage the dateFormattingInfo object for custom JS date parsing or localized messages.

function showFormattedDateExample() {
    const format = Xrm.Utility.getGlobalContext().userSettings.dateFormattingInfo;
    console.log("User's long date pattern: " + format.LongDatePattern);
}

🔐 Scenario 5: Fetch Detailed Role Privilege Info

Let’s say you want to conditionally show/hide controls based on fine-grained privileges, not just role names.

function checkPrivilegeAccess() {
    const userSettings = Xrm.Utility.getGlobalContext().userSettings;

    userSettings.getSecurityRolePrivilegesInfo().then((privileges) => {
        const hasDeleteAccess = Object.values(privileges).some(p => p.privilegeName === "prvDeleteAccount" && p.depth > 0);

        if (!hasDeleteAccess) {
            alert("You do not have delete privileges on Accounts.");
        }
    });
}

This is especially useful in complex role-based security models where teams and BU contexts affect privilege depth.


🕒 Scenario 6: Handle Time Zone-Specific Logic

Need to show a warning if an action is being performed outside business hours in the user’s local time zone?

function warnIfOutsideBusinessHours() {
    const offset = Xrm.Utility.getGlobalContext().userSettings.getTimeZoneOffsetMinutes(); // e.g., -600 for AEDT
    const nowUTC = new Date();
    const localTime = new Date(nowUTC.getTime() - offset * 60000);
    const hour = localTime.getHours();

    if (hour < 9 || hour > 17) {
        console.warn("You're working outside business hours!");
    }
}

✅ Summary of Properties You Should Know

PropertyUse Case
userName, userIdIdentify current user
rolesCheck assigned roles dynamically
languageIdAdjust UX for localization
transactionCurrencyCurrency-based logic
isRTL, isHighContrastEnabledAccessibility features
dateFormattingInfoDate parsing/display based on locale
defaultDashboardIdCustom navigation behavior
getSecurityRolePrivilegesInfo()Fine-grained access checks
getTimeZoneOffsetMinutes()Time zone-aware logic

The userSettings object isn’t just metadata, it’s the key to building responsive, inclusive, and context-aware user experiences in Dynamics 365.

Whether you’re adapting based on currency, time zone, or accessibility preferences, it lets your app “know” who it’s working with and behave accordingly.

Leave a comment