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.
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.
LikeLike
[…] Courtesy: https://d365dev.com/2018/04/20/disable-editing-of-specific-financial-dimensions-on-form/ […]
LikeLike
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.
LikeLike