2019-09-12

[AX2012] Get Default Dimension Value and Description

This is a job to show value and description of a default dimension.

static void defaultDimension(Args _args)
{
    PurchLine                           purchLine;
    DimensionAttributeValueSetStorage   dimStorage;
    int                                 counter;
    container                           attribute = ["BusinessUnit", "Department", "ItemGroup"];
    DimensionAttribute                  dimensionAttribute;
    DimensionAttributeValue             dimensionAttributeValue;
    ;
   
    purchLine = PurchLine::findRecId(35637329190);//sample to get default dimension
    dimStorage = DimensionAttributeValueSetStorage::find(purchLine.DefaultDimension);
    //all attribute
    for (counter= 1 ; counter<= dimStorage.elements() ; counter++)
    {
        dimensionAttribute = DimensionAttribute::find(dimStorage.getAttributeByIndex(counter));
        dimensionAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute, dimStorage.getDisplayValueByDimensionAttribute(dimensionAttribute.RecId));
        info(strFmt("%1 - %2", dimStorage.getDisplayValueByDimensionAttribute(dimensionAttribute.RecId), dimensionAttributeValue.getName()));
    }
   
    //specific attribute
    for (counter= 1 ; counter<= conLen(attribute) ; counter++)
    {
        dimensionAttribute = DimensionAttribute::findByName(conPeek(attribute, counter));
        dimensionAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute, dimStorage.getDisplayValueByDimensionAttribute(dimensionAttribute.RecId));
        info(strFmt("%1 - %2", dimStorage.getDisplayValueByDimensionAttribute(dimensionAttribute.RecId), dimensionAttributeValue.getName()));
    }
}