Disable editing of specific financial dimensions on form – with fix

I’ve see this code (or very similar patterns) blogged and re-blogged in several places as a way to disable editing of specific financial dimensions on a form in X++:

[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 // should be noneditable
        && dimensionAttribute.Name != contractType // should be noneditable
    join dimAttrSetItem
    where dimAttrSetItem.DimensionAttribute == dimensionAttribute.RecId
        && dimAttrSetItem.DimensionAttributeSet == dimensionSetId
    {
        dimensionAttributeSetStorage.addItem(
        dimensionAttribute.RecId,
        dimensionAttribute.HashKey,
        NoYes::Yes);
    }

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

However, I recently had it stop working after a Microsoft “proactive quality update.” After a bit of research, here’s the fix: add a final line at the end:

    dimControl.reactivate();

I hope this saves you some frustration!

Unknown's avatar

Author: brian j. parker

Brian's just this guy, you know?

Leave a comment

Design a site like this with WordPress.com
Get started