axaptax++dynamics-ax-2012-r3

Dynamic AX 2012 R3 Write Empty Financial Dimensions of Customer


How can i write all dimensions of customer? I can use this code but it result just Department = 022.

CustTable                         custTable = CustTable::find("10112");
DimensionAttributeValueSetStorage dimStorage;
Counter i;

dimStorage = DimensionAttributeValueSetStorage::find(custTable.DefaultDimension);

for (i=1 ; i<= dimStorage.elements() ; i++)
{
    info(strFmt("%1 = %2", DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name,
                           dimStorage.getDisplayValueByIndex(i)));

But i want if dimension is empty result is empty. For the example below result should be like this;

BusinessUnit = 
Department   = 022
Project      = 
ServiceLine  =

related image

How can i do this?


Solution

  • Try changing your code to the below. I don't have the same dimension that you have, so you might need to tweak it.

    CustTable                               custTable       = CustTable::find("10112");
    DimensionAttribute                      segment         = DimensionAttribute::findByName('Segment');
    DimensionAttribute                      department      = DimensionAttribute::findByName('Department');
    DimensionAttribute                      businessType    = DimensionAttribute::findByName('BusinessType');
    DimensionAttribute                      serviceLine     = DimensionAttribute::findByName('ServiceLine');
    DimensionAttributeValueSetStorage       dimStorage;
    
    dimStorage = DimensionAttributeValueSetStorage::find(custTable.DefaultDimension);
    
    info(strFmt("%1 = %2", segment.Name, dimStorage.getDisplayValueByDimensionAttribute(segment.RecId)));
    info(strFmt("%1 = %2", department.Name, dimStorage.getDisplayValueByDimensionAttribute(department.RecId)));
    info(strFmt("%1 = %2", businessType.Name, dimStorage.getDisplayValueByDimensionAttribute(businessType.RecId)));
    
    // You make need to tweak these
    info(strFmt("%1 = %2", serviceLine.Name, dimStorage.getDisplayValueByDimensionAttribute(serviceLine.RecId)));