web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
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

I have the same question (0)
  • Suggested answer
    Mohit Rampal Profile Picture
    12,565 Moderator on at

    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 683 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 563 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 398 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans