Default dimensions in AX 2012

Creating default dimensions for vendor or customer through X++:

Created a class called “FindOrCreateDefaultDimension” and then utilizing its method “findDefaultDimension” whenever default dimension is required.

Suppose I’ve 6 dimension out of which 3 are custom dimension and rest are standard ones. For custom dimension am including ‘FinancialDimensionTag’ Table in to the while loop. As shown below


Static DimensionDefault findDefaultDimension(str _Department, Str _BusinessType,str _AnchorTenant, Str _Category,str _SiteId, str _costcenter, str _purpose)
{

    Struct                          struct = new Struct();
    container                       defDimensionCon;
    DimensionDefault                dimensionDefault;
    DimensionAttributeSetItem       dimAttrSetItem;
    DimensionAttribute              dimAttribute;
    int i;

    //Loop for required dimensions
    while select Name, BackingEntityType from dimAttribute
        where dimAttribute.BackingEntityType == tableNum(DimAttributeOMBusinessUnit) ||
              dimAttribute.BackingEntityType == tableNum(DimAttributeOMDepartment) ||
              dimAttribute.BackingEntityType == tableNum(DimAttributeOMCostCenter) ||
              dimAttribute.BackingEntityType == tableNum(DimensionFinancialTag) &&
              dimAttribute.Type              != DimensionAttributeType::DynamicAccount
              join dimAttrSetItem
                where dimAttrSetItem.DimensionAttribute == dimAttribute.RecId &&
                      dimAttrSetItem.DimensionAttributeSet == DimensionCache::getDimensionAttributeSetForLedger()
    {
        //Add the Dimension name and display value to struct

        if (dimAttribute.BackingEntityType == tableNum(DimAttributeOMDepartment))
        {
            struct.add(dimAttribute.Name, _Department);
        }
       if (dimAttribute.BackingEntityType == tableNum(DimensionFinancialTag) && dimAttribute.Name == 'BusinessType')
        {
            struct.add(dimAttribute.Name, _BusinessType);
        }
        if (dimAttribute.BackingEntityType == tableNum(DimensionFinancialTag) && dimAttribute.Name == 'AnchorTenant')
        {
            struct.add(dimAttribute.Name, _AnchorTenant);
        }
        if (dimAttribute.BackingEntityType == tableNum(DimensionFinancialTag) && dimAttribute.Name == 'Category')
        {
            struct.add(dimAttribute.Name, _Category);
        }
        if (dimAttribute.BackingEntityType == tableNum(DimensionFinancialTag) && dimAttribute.Name == 'SiteId')
        {
            struct.add(dimAttribute.Name, _SiteId);
        }
        if (dimAttribute.BackingEntityType == tableNum(DimAttributeOMCostCenter))
        {
            struct.add(dimAttribute.Name, _costcenter);
        }

    }

    defDimensionCon += struct.fields();

    for (i = 1; i <= struct.fields(); i++)
    {
        defDimensionCon += struct.fieldName(i);
        defDimensionCon += struct.valueIndex(i);
    }

        if (struct.fields())
    {
        //Get the DimensionAttributeValueSet table’s Record ID
        dimensionDefault = AxdDimensionUtil::getDimensionAttributeValueSetId(defDimensionCon);

    }
    return dimensionDefault;


}



And now am going to use the above created class to update the vendor financial dimensions.



static void Updating_VendorDefaultDimension(Args _args)
{
    VendTable       vt;
    ;

    vt = VendTable::find("VT-1003", true);

    vt.DefaultDimension = FindOrCreateDefaultDimension::findDefaultDimension("00000063", "", "", "", "", "OU_4612", "");

    vt.update();
}



Running the above job will results in to:



Happy Daxing J Stay tuned for more…


No comments

The Moment Tokens, Vectors, and Models Click, AI Starts Making Sense

  You've probably heard these terms dozens of times by now. They're showing up in AI discussions, Copilot demos, Azure OpenAI conver...

Powered by Blogger.