venerdì 12 aprile 2024

AX2012/D365- HOW TO EXTRACT ALL MAINACCOUNT ALLOCATION RULES by code X++

This article is a merely starting point.
In AX2012 / D365 we can handle the cost allocation by parameters.

Ledger allocation rules are used to automatically calculate and generate allocation journals and account entries for the allocation of ledger balances or fixed amounts. Allocation methods can be variable or fixed. The allocation is based on the transaction currency value.

  • We can split the cost to different/several Financial Dimensions (in percentage); By Company etc...

Microsoft documentation:
AX2012:
https://learn.microsoft.com/en-us/dynamicsax-2012/appuser-itpro/create-an-allocation-rule

D365:
https://learn.microsoft.com/en-us/dynamics365/finance/general-ledger/ledger-allocation-rules

Data to extract:

what I would like to extract

JOB x++
By code x++ it is possible. The job below can exttract in a infolog the data:
it be can improve

Str1260 mainAccount_Name, DimFinanancial_Name;
MainAccount account;
DimensionAttributeValueSetItem valueSetItem;
DimensionAttributeValue dimAttrValue;
DimensionAttribute dimAttr;
Str1260 dimensionAttributeNames;
LedgerAllocation allocation;
DefaultDimensionView dimensionView;
DimensionAttribute dimensionAttribute; 
   
 while select allocation
 {
     select Name, MainAccountId from account where account.RecId ==    allocation.FromMainAccount;

        mainAccount_Name = account.Name; // to chek the value
      
     while select dimAttr
        exists join dimAttrValue
            where dimAttrValue.DimensionAttribute == dimAttr.RecId
        exists join valueSetItem
            where valueSetItem.DimensionAttributeValue == dimAttrValue.RecId
                && valueSetItem.DimensionAttributeValueSet == allocation.ToDefaultDimension
        {

            DimFinanancial_Name= dimAttr.Name; // to check the value
           
                    select firstOnly dimensionView
                    where dimensionView.DefaultDimension == allocation.ToDefaultDimension
                join dimensionAttribute
                    where dimensionView.Name == dimensionAttribute.Name
                    && dimensionView.Name == DimFinanancial_Name;
      // OUTPUT
            info(strFmt("%1;%2;%3;%4;%5",
            mainAccount_Name, account.MainAccountId,
            DimFinanancial_Name,dimensionView.DisplayValue,allocation.Value));

        }       
    } 
RESULT:





Nessun commento:

Posta un commento