Header Ads Widget

👤 Working with User License and Default Dimensions in D365FO Using X++

 

📌 Overview

In this post, you'll learn how to:

  1. ✅ Retrieve dimension values from a DefaultDimension

  2. ➕ Create or merge a new default dimension value

  3. 📄 Create a Ledger Journal Header

  4. 🔒 Check a user's assigned license types using SecurityLicenseRole


📘 Prerequisites

Make sure the following references are available in your project:

csharp
using Microsoft.Dynamics.AX.Security.Management; using Microsoft.Dynamics.AX.Security.Management.Querying; using Microsoft.Dynamics.AX.Security.Management.UI;

🧩 Retrieve Dimension Value from Default Dimension

x++
public static str getDimensionValueString(DimensionDefault defaultDim) { DefaultDimensionView dimView; str resultValue; while select dimView where dimView.DefaultDimension == defaultDim { resultValue += dimView.DisplayValue + "~"; } return resultValue; }

📝 This method loops through the dimension values stored in a default dimension and concatenates them using ~ as a delimiter.


🛠️ Create or Update a Default Dimension Value

x++
public static DimensionDefault buildOrMergeDefaultDimension(Name dimName, str dimValue, DimensionDefault existingDim = 0) { DimensionAttributeValueSetStorage valueStorage = new DimensionAttributeValueSetStorage(); DimensionAttribute attr = DimensionAttribute::findByName(dimName); if (attr.RecId && dimValue) { DimensionAttributeValue attrValue = DimensionAttributeValue::findByDimensionAttributeAndValueNoError(attr, dimValue, false, true); valueStorage.addItem(attrValue); } DimensionDefault newDim = valueStorage.save(); return LedgerDimensionDefaultFacade::serviceMergeDefaultDimensions(newDim, existingDim); }

📝 This method creates a new dimension value or merges it with an existing default dimension.


📘 Create a Ledger Journal Header Programmatically

x++
public static LedgerJournalTable generateLedgerJournal(LedgerJournalNameId journalName, CurrencyCode currencyCode = "") { LedgerJournalTable jourTable; LedgerJournalTableData tableData = JournalTableData::newTable(jourTable); jourTable.JournalNum = tableData.nextJournalId(); jourTable.JournalName = journalName; jourTable.initFromLedgerJournalName(journalName); if (currencyCode) jourTable.CurrencyCode = currencyCode; jourTable.insert(); return jourTable; }

📝 Used to generate a new ledger journal record via code.


🔒 Check If a User Has a Specific License Type

x++
public static boolean hasUserLicense(UserLicenseType licenseToCheck, UserId userId = curUserId()) { SecurityLicenseRole licenseRole; SecurityRole role; SecurityUserRole userRole; boolean found = false; DialogService::PopulateSysSecurityRolesWithAggregateLicense(SecurityLicenseRole.getPhysicalTableName(), SysSecurity::GetSecurityRepository()); while select role exists join userRole where userRole.User == userId && userRole.SecurityRole == role.RecId { select firstonly licenseRole where licenseRole.SecurityRole == role.RecId; if (licenseRole.RecId) { List licenseList = strSplit(licenseRole.License, ','); ListIterator iterator = new ListIterator(licenseList); while (iterator.more()) { UserLicenseType currentLicense = any2Enum(iterator.value()); if (currentLicense == licenseToCheck) { found = true; break; } iterator.next(); } } } return found; }

📝 This function iterates over a user’s assigned security roles and checks whether any of the roles include the specified license type.


📚 Reference


✅ Summary

This guide covered essential methods for:

  • Interacting with Default Dimensions

  • Dynamically generating ledger journal headers

  • Verifying license types assigned to a user

These utilities are extremely useful for building automation, compliance validation, or administrative tools in your D365FO implementations.

Post a Comment

0 Comments