Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

Disable Purchase requisitions Line financial dimension Main Account based on custom condition through X++ code in D365 F&O

(0) ShareShare
ReportReport
Posted on by 73

Hallo,

i want to disable MainAccount in financial dimension Purchase requisitions Line,

pastedimage1684218175590v1.png

but its error Object reference not set to an instance of an object., need advise for my case how can i solve ?

my reference to link :

https://d365dev.com/2018/04/20/disable-editing-of-specific-financial-dimensions-on-form/

i just change event handler to 

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

const str MainAccounttmp = 'MainAccount';

dimensionAttributeSetStorage = new DimensionAttributeSetStorage();

while select dimensionAttribute
where dimensionAttribute.Name != MainAccounttmp // 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());
}

Thanks

  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,552 Super User 2024 Season 1 on at
    RE: Disable Purchase requisitions Line financial dimension Main Account based on custom condition through X++ code in D365 F&O

    Hi Dodi, The issue is in below line. 'DimensionEntryControlTable' form control exists in SalesTable form, as the article is using SalesTable so no issues for that code. However, you are trying to use same control name in PurchReqTable and this form does not have control under the name 'DimensionEntryControlTable'.

    Try replacing it with 'LineDimensionEntryControl' as that's the control name for Financial Dimensions at line level

    Issue:
    DimensionEntryControl dimControl = _sender.design().controlName(identifierStr(DimensionEntryControlTable));
    
    Fix:
    
    DimensionEntryControl dimControl = _sender.design().controlName(identifierStr(LineDimensionEntryControl));

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,965 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,817 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans