AX2012 – Create default dimension with a set of dimension values

The following job will get a DimensionAttributeValueSet record ID base on the a set of dimension values.


static void DEV_CreateDefaultDimension(Args _args)
{
    DimensionAttributeValueSetStorage   valueSetStorage = new DimensionAttributeValueSetStorage();
    DimensionDefault                    result;  
   
    int                     i;
    DimensionAttribute      dimensionAttribute;
    DimensionAttributeValue dimensionAttributeValue;
   
    // 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();  
}

** The above is for interest only and comes with no warranties **

Comments

  1. Hello,

    When I run the job to create default dimension, I get following error
    "Unable to return DimensionAttributeValue record for 00000028".
    What could be reason? I need to insert values into standard dimension.

    ReplyDelete
    Replies
    1. Yes, the dimension value has to exist (e.g. There should be a department 00000028 in the system) otherwise DimensionAttributeValue creation will fail.

      Delete
  2. Hello,
    It helped very much. But it create every dimension with different DefaultDimesion. Is this possible to have same defaultdimension for every created dimension.

    ReplyDelete
    Replies
    1. Hi, I am not sure what you mean. Can you elaborate?

      FYI, the job above:
      - Creates a DimensionAttributeValue record if it does not exists. (This is a reference between the DimensionAttribute and the value from the source [e.g. a Customer group]. The value must already exists at the source otherwise it'll fail.)
      - Based on the found/created DimensionAttributeValue, find the corresponding DimensionAttributeValueSet record. It will create one if no existing record matches the set.

      In the end, if you are using the code above to, say, genereate DefaultDimension during Customer import. Then for customers who have the same set of financial dimension values, they'll have the same DefaultDimension (recId) value as well.

      Delete
  3. Thanks Matte, this is really helpful without wasting any time :)

    ReplyDelete

Post a Comment