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

Announcements

News and Announcements icon
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,573 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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

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

#1
Martin Dráb Profile Picture

Martin Dráb 341 Most Valuable Professional

#2
CU10121822-0 Profile Picture

CU10121822-0 312

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 262 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans