Create Default dimension - Ax 2012

Hi,
The below code is used to create the default dimension in ax 2012.

static void CreateDefaultDimension(Args _args)
{
    DimensionAttributeValueSetStorage valueSetStorage = new DimensionAttributeValueSetStorage();
    DimensionDefault result;

    DimensionAttribute dimensionAttribute;

    DimensionAttributeValue dimensionAttributeValue;
    int i;

    // Note that "Item" is not one of the default dimension,
    // but DimensionAttributeValueSetStorage will handle it gracefully
    container conAttr = ["Department", "ExpensePurpose", "Item"];
    container conValue = ["00000028", "Training", "1000"];
    str dimValue;

    for (i = 1; i <= conLen(conAttr); i++)
    {
 
       dimensionAttribute = dimensionAttribute::findByName(conPeek(conAttr,i));
        if (dimensionAttribute.RecId == 0)
        {
 
          continue;
        }
     

        dimValue = conPeek(conValue,i);
        if (dimValue != "")
        {
            // The last parameter is "true". A dimensionAttributeValue record will be created if not found.

            dimensionAttributeValue =
    
         dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,dimValue,false,true);

            // Add the dimensionAttibuteValue to the default dimension
            valueSetStorage.addItem(dimensionAttributeValue);
        }
    }

    result = valueSetStorage.save();
    info(result);
}
 

Comments

Popular posts from this blog

x++ code to Generate cheque for vendor payment journal

Import Procurement Hierarchy / Categories with out code in ax 2012

Copy favorites From one user to another user - Ax 2012