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:





lunedì 1 aprile 2024

AX 2012 - D365FFO - Aggiungere controlli ad una form dinamicamente e gestire gli eventi (registerOverrideMethod)

In questo post vediamo come aggiungere a run time dei controlli ad una form e gestire gli eventi dei controlli. 

La form di base conterrà un button group a cui aggiungeremo tre pulsanti ed un gruppo a cui aggiungeremo un enumerato ed una stringa. 

Dei tre pulsanti gestiamo l'evento mouseDown (in D365 l'evento mouseDown è deprecato) per capire se il pulsante è stato premuto col pulsante destro oppure col sinistro; dell'enumerato gestiamo l'evento selectionChanged e del campo stringa l'evento modified.

Sia l'aggiunta dei controlli che gli event handler vanno aggiunti nella init della form:

 public void init()  
 {  
   int         i;  
   FormButtonControl  button;  
   FormComboBoxControl comboBox;  
   FormStringControl  stringControl;  
   
   super();  
   
   for(i = 0; i < 3; i++)  
   {  
     button = ButtonGroup.addControl(FormControlType::Button, strFmt("button_%1",i+1));  
     button.text(strFmt("%1",i+1));  
     button.registerOverrideMethod(methodStr(FormButtonControl, mouseDown), identifierStr(buttonMouseDown), this);  
   }  
     
   comboBox = ControlGroup.addControl(FormControlType::ComboBox, "InventCustVend_Combo");  
   comboBox.enumType(enumNum(ModuleInventCustVend));  
   comboBox.registerOverrideMethod(methodStr(FormComboBoxControl, selectionChange), identifierStr(ComboSelectionChange), this);  
     
   stringControl = ControlGroup.addControl(FormControlType::String, "Description_Text");  
   stringControl.extendedDataType(extendedTypeNum(Description));  
   stringControl.registerOverrideMethod(methodStr(FormStringControl, modified), identifierStr(modifiedString), this);    
 }  
I tre event handler vanno aggiunti a livello di form:
 public void buttonMouseDown(int _x, int _y, int _button, boolean _Ctrl, boolean _Shift,FormButtonControl _btn)  
 {  
   switch(_button)  
   {  
     case 1:  
       info(strFmt("hai premuto il bottone '%1' col pulsante %2",_btn.name(),"sinistro"));  
       break;  
   
     case 2:  
       info(strFmt("hai premuto il bottone '%1' col pulsante %2",_btn.name(),"destro"));  
break; } }
 public int comboSelectionChange(FormComboBoxControl _comboBox)  
 {  
   info(strFmt("L'enumerato è cambiato %1",_comboBox.selection()));  
     
   return 1;  
 }  
 public boolean modifiedString(FormStringControl _stringControl)  
 {  
   boolean ret = true;  
     
   info(strFmt("nuovo valore '%1'",_stringControl.text()));  
     
   return ret;  
 }  
Tutti i metodi per gestire gli eventi prendono il controllo come parametro. Se l'event prevede altri parametri standard, come nel caso mouseDown, il controllo và aggiunto come ultimo parametro.