Saturday, 13 June 2020

Find and Update the Default Dimension in AX 2012 R3 Using X++ Code

In this we are going to see how to find  or update default dimension value for an Item/Customer/Vendor.

Find Default Dimension value :

Display DimensionValue MKDim_Product()
{
    DimensionAttributeValueSetStorage   dimStorage;
    DimensionValue                      product;
    Counter                             i;
    #define.Product("Product")
//Note This in the below line can be replaced with InventTable /CustTable /VendTable
    dimStorage = DimensionAttributeValueSetStorage::find(this.DefaultDimension);

    for (i= 1 ; i<= dimStorage.elements() ; i++)
    {
        if(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name == #Product)
        {
            product = dimStorage.getDisplayValueByIndex(i);
        }
    }

    return product;
}

Update /Modify Default Dimension value:

//Note _defaultDimensino in the below line can be replaced with InventTable.DefaultDimension /CustTable.DefaultDimension /VendTable.DefaultDimension
//defaultDimension    = InventTable::find(itemId).DefaultDimension;
private void updateDimension(str _dimName, str _dimVal, DimensionDefault _defaultDimension)
{

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


    ttsBegin;
    if (_defaultDimension && _dimVal)
    {
       
        dimStorage          = DimensionAttributeValueSetStorage::find(defaultDimension);
        dimAttribute        = DimensionAttribute::findByName(_dimName);
        dimAttributeValue   = DimensionAttributeValue::findByDimensionAttributeAndValue(dimAttribute, _dimVal, true, true);

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

}

How to Disable “Advanced Filter or Sort” and Enforce Custom Filters on Any D365FO Form

 In Dynamics 365 Finance and Operations, users can apply filters through the “Advanced filter or sort” feature found under the Options tab...