Disable editing of specific financial dimensions on form

The form control “DimensionEntryControl” has a method called “parmEditableDimensionSet” which sets only a specific dimension set as editable. Thus, by excluding financial dimensions from the dimension set, it is possible to make specific dimension not editable.

First, a dimension set storage needs to be created. After that, each financial dimension will be added to the dimension set storage excluding the dimensions which should not be editable. At the end, the dimension set storage will be passed to the mentioned parm-method “parmEditableDimensionSet” which then only sets the dimensions in the dimension set storage as editable.

Below is an example which implements the code in the form event handler “OnInitialized” to make dimension not editable upon calling a form.

[FormEventHandler(formStr(SalesTable), FormEventType:Initialized)]
public static void SalesTable_OnInitialized(xFormRun _sender, FormEventArgs _e)
{
    DimensionEntryControl dimControl = _sender.design().controlName(identifierStr(DimensionEntryControlTable));
    DimensionEnumeration dimensionSetId = DimensionCache:getDimensionAttributeSetForLedger();
    DimensionAttributeSetStorage dimensionAttributeSetStorage;
    DimensionAttribute dimensionAttribute;
    DimensionAttributeSetItem dimAttrSetItem;

    const str contractNumber = 'ContractNo';
    const str contractType = 'ContractType';

    dimensionAttributeSetStorage = new DimensionAttributeSetStorage();

    while select dimensionAttribute
        where dimensionAttribute.Name != contractNumber // Exclude specific dimension which should be not editable
            && dimensionAttribute.Name != contractType // Exclude specific dimension which should be not editable
        join dimAttrSetItem
            where dimAttrSetItem.DimensionAttribute == dimensionAttribute.RecId
                && dimAttrSetItem.DimensionAttributeSet == dimensionSetId
    {
        dimensionAttributeSetStorage.addItem(
            dimensionAttribute.RecId,
            dimensionAttribute.HashKey,
            NoYes::Yes);
    }

    dimControl.parmEditableDimensionSet(dimensionAttributeSetStorage.save());
}

As a result, the dimension fields “ContractNo” and “ContractType” are no longer editable on the sales order form.

findim

4 thoughts on “Disable editing of specific financial dimensions on form

  1. Thanks so much!.. I was looking for this and took me a while but finally found the solution on this article, most of the information on the web on this topic is for older versions of AX but there is almost nothing for D365, you make me the day be sooo happyyyy!.. I really appreciate it.

    Like

  2. One comment on this. This works fine if you are doing this when the form is initially opened. However if you require the control to be dynamically updated (e.g. from the datasource active()) then you need to add a call to dimControl.run() right at the end. That re-executes the logic to update the design based on any changes.

    Like

  3. As stated by andrewtravels, trying to put your customization in an extension of formDataSourceStr (or formControlStr) may require some double calls to make it work. This is caused by native logic within DimensionEntryControl class (method onDimensionSetChanged) to skip the call to activateControl even if editable dimension set is modified.

    I submitted an extensibility request to Microsoft to kinkdly ask them to improve their native logic. But it was rejected. They answer back that any custom logic used to disable financial dimension segment should be done using the controller class.

    For example, let say I want to disable a segment within SalesLine.DefaultDimension. This field extends InventSiteLinkedDimensionValueSet. The extended data type relates to class InventSiteLinkedDimensionEntryController (see System.ComponentModel.Composition.ExportMetadataAttribute attribute). Then using CoC to create an extension of this class (or LedgerDefaultDimensionEntryController which is the parent) to put the customization in method onValueSetLoad to affect the content of this.parmDimensionsToAllowEdit.

    Like

Leave a comment