D365FFO – AX – Modify / Update the Default Dimension in AX 2012 R3 Using X++ Code.

Modify/ Update the Default Dimension  in AX 2012 R3 Using X++ Code.

static void RB_ModifyDimension(Args _args)
{

    ItemId      itemId;
    str         costCentre;

    DimensionAttributeValueSetStorage   dimStorage = new DimensionAttributeValueSetStorage();
    DimensionAttribute                  dimAttribute;
    DimensionAttributeValue             dimAttributeValue;
    DimensionDefault                    defaultDimension;

    #define.CostCentre(‘CostCentre’)

    itemid     =  “TESTItem”;
    costCentre = ‘2000’;

    ttsBegin;
    if (itemid && costCentre)
    {

        defaultDimension    = InventTable::find(itemId).DefaultDimension;
        dimStorage          = DimensionAttributeValueSetStorage::find(defaultDimension);
        dimAttribute        = DimensionAttribute::findByName(#CostCentre);
        dimAttributeValue   = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAttribute, costCentre, true, true);

        dimStorage.addItem(dimAttributeValue);
        // Dimension modified or updated including costcentre as well.
        defaultDimension = dimStorage.save();

        info(strFmt(“Modified/ Updated Default Dimension %1”, defaultDimension));

    }
    ttsCommit;

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s