RSS

Dynamics AX Ledger Dimension using DimensionServiceProvider

27 Mar

There are different ways to create combinations of dimension using X++ code.

in previous blog  i have written how to create ledger dimension using class AxdDimensionUtil method getledgerAccountid which takes container as input and container has account entry pattern along with dimensions.for more details look in to this Dynamics AX Ledger Dimension using AxdDimensionUtil::getLedgerAccountId

These combinations are saved as records in the DimensionAttributeValueCombination table.The RecId from the DimensionAttributeValueCombination table is what is saved in the LedgerDimension field on the LedgerJournalTrans table.

The  table DimensionAttributeValueCombination as it stores a full multi-segment account combination along with some de-normalized information about the combination such as the concatenated segments as a single string, a foreign key (FK) reference to the Account structure, and a FK to the MainAccount that was used.

The best way to create dimension combinations is to use the class and method DimensionServiceProvider\buildDimensionStorageForLedgerAccount.

The buildDimensionStorageForLedgerAccount method takes a LedgerAccountContract class. In the LedgerAccountContract class there are two parm methods, parmMainAccount and parmValues. The parmMainAccount method takes the MainAccount like ‘10060’ and the parmValues method takes a list of the other dimension values you want to set.

More specifically the parmValues method takes a list of classes. The classes are of type DimensionAttributeValueContract. On the DimensionAttributeValueContract class you set two methods, parmName and parmValue. For example, ‘Branch’ for the name and ‘Mumbai’ for the value.

Build up a list of DimensionAttributeValueContract classes for each dimension you want to specify and then pass the list to the parmValues method on the LedgerAccountContract class. Once you have the LedgerAccountContract built up send it to the DimensionServiceProvider\buildDimensionStorageForLedgerAccount.

The following code can be used to update LedgerDimension field on the LedgerJournalTrans

RecId getDimension(str _ledgerAccount, str _branch, str _serviceCentre, str _department)  
 {  
   DimensionServiceProvider      DimensionServiceProvider = new DimensionServiceProvider();  
   LedgerAccountContract        LedgerAccountContract = new LedgerAccountContract();  
   DimensionAttributeValueContract   ValueContract;  
   List                ListValueContract = new List(Types::Class);  
   dimensionAttributeValueCombination dimensionAttributeValueCombination;  
   DimensionStorage          dimStorage;  
   if (_businessUnit)  
   {  
     ValueContract = new DimensionAttributeValueContract();  
     ValueContract.parmName('Branch') ;  
     ValueContract.parmValue(_branch);  
     ListValueContract.addEnd(ValueContract);  
   }  
   if (_costCentre)  
   {  
     ValueContract = new DimensionAttributeValueContract();  
     ValueContract.parmName('Serviceentre') ;  
     ValueContract.parmValue(_serviceCentre);  
     ListValueContract.addEnd(ValueContract);  
   }  
   if (_department)  
   {  
     ValueContract = new DimensionAttributeValueContract();  
     ValueContract.parmName('Department') ;  
     ValueContract.parmValue(_department);  
   }  
   
   LedgerAccountContract.parmMainAccount(_ledgerAccount);  
   LedgerAccountContract.parmValues(ListValueContract);  
   dimStorage = DimensionServiceProvider::buildDimensionStorageForLedgerAccount(LedgerAccountContract);  
   dimensionAttributeValueCombination = DimensionAttributeValueCombination::find(dimStorage.save());  
   return dimensionAttributeValueCombination.RecId;  
 }
Advertisements
 

Tags: , , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: