How to find Default Financial Dimensions (X++)

Hi, in this post i am goint to show you two ways of how to select default dimension values in AX 2012.

1) Traditional select codes: You can do a "while select" or just "select firstonly" for your needs. You can get all dimensions with "while select"  and just one with the "select firstonly" as you know. But if you are going to use "select firstonly", you must specify the dimension attribute first.

Let's assume that you need to find the default financial dimensions of a specific customer record;

Select Firstonly:

Below code shows you the Dimension Attribute name and value of the selected customer.

    CustTable                               custTable;
    DimensionAttributeValueSetItem          DimensionAttributeValueSetItem;
    DimensionAttributeValue                 DimensionAttributeValue;
    DimensionAttribute                      DimensionAttribute;
    
    select firstonly custTable
            where custTable.AccountNum == "‪‪‪exampleCustAccountNum" //Selected your customer and so the default dimension  
    join DimensionAttributeValueSetItem
            where DimensionAttributeValueSetItem.DimensionAttributeValueSet == custTable.DefaultDimension
    join DimensionAttributeValue
            where DimensionAttributeValue.RecId == DimensionAttributeValueSetItem.DimensionAttributeValue
    join DimensionAttribute
            where   DimensionAttribute.RecId == DimensionAttributeValue.DimensionAttribute
            &&      DimensionAttribute.Name == "DimensionName";  //Specify the default dimension that you need from DimensionAttribute table 
        {
            info(strFmt("%1--%2",DimensionAttribute.Name,DimensionAttributeValueSetItem.DisplayValue));
        }


While Select:

Below code shows you all the Dimension attribute names and values of the selected customer.

    CustTable                               custTable;
    DimensionAttributeValueSetItem          DimensionAttributeValueSetItem;
    DimensionAttributeValue                 DimensionAttributeValue;
    DimensionAttribute                      DimensionAttribute;
    
   while select custTable
            where custTable.AccountNum == "‪‪‪exampleCustAccountNum" //Selected your customer and so the defautl dimension
    join DimensionAttributeValueSetItem
            where DimensionAttributeValueSetItem.DimensionAttributeValueSet == custTable.DefaultDimension
    join DimensionAttributeValue
            where DimensionAttributeValue.RecId == DimensionAttributeValueSetItem.DimensionAttributeValue
    join DimensionAttribute
            where   DimensionAttribute.RecId == DimensionAttributeValue.DimensionAttribute
        {
            info(strFmt("%1--%2",DimensionAttribute.Name,DimensionAttributeValueSetItem.DisplayValue));
        }
    

You can modify these queries for your needs. (For example, if you have Default Dimension RecId, you can delete custTable selection... etc.)


2) System classes: You can use system classes to find the default dimension values.

Below code finds the default dimension value with the help of the "DimensionAttributeValueSetStorage" class.


    DimensionAttributeValueSetStorage dimStorage;
    ;

    dimStorage = DimensionAttributeValueSetStorage::find(DefaultDimRecId); //Send the Default Dimension Id

    info(dimStorage.getDisplayValueByDimensionAttribute(DimensionAttribute::findByName("DimensionName").RecId)); // Specify the Default Dimension Name


Comments

Popular posts from this blog

How to find Company Logo (X++)

How to find MainAccount with LedgerDimension (X++)

How to do barcode in SSRS (X++)