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

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)
Suggested answer

Can we override private method in X++

(1) ShareShare
ReportReport
Posted on by 515

Hi All,

I wanted to know if we can override Private method of child class into parent class ? If yes how?

If no then is there any way to do below issue?

In FormletterParmData ->Reaarange () I have written some custom code which works fine in all condition but when I calls Batch job it is creating issue.

So I wanted to write same code in SalesFormLetterParmDataInvoice. but it is throwing error as this rearrange method is private in FormletterParmData class. Please suggest how to handle this?

*This post is locked for comments

I have the same question (0)
  • Mea_ Profile Picture
    60,284 on at
    RE: Can we override private method in X++

    1) You cannot override private method it contradicts OOP

    2) What kind of issue do you have in batch? Could you please share some details

  • Asim Saeed Profile Picture
    575 on at
    RE: Can we override private method in X++

    Adding custom code in the core classes itself is not a good Idea. Go for 'Eventing' or 'Inheritance' as the first place.

  • Dhanshri Profile Picture
    515 on at
    RE: Can we override private method in X++

    In batch job, I have used some Sysglobalcache variables which I am setting from my custom batch jobs and my custom form doing sales invoice.

    When I am calling formletterParmData->rearrange() from Batch it is not getting Sysglobalcache  vaule(which I am setting from my custom form) and so the error was coming if I comment this code it will work fine.

    so I decided to override this method in subclass i.e SalesFormLetterParmDataInvoice.

  • Dhanshri Profile Picture
    515 on at
    RE: Can we override private method in X++

    can you pls let me know the sample code for 'Eventing' or 'Inheritance'. I never used it.

  • Mea_ Profile Picture
    60,284 on at
    RE: Can we override private method in X++

    You are doing very strange things. AX can have hundreds of concurrent users and hundreds of batch thread running simultaneously and playing with global cache is the last thing you want to do. You need to pass your parameter all the way through from your custom form to sales invoice posting if form instantiate this process.

    However if you are doing some setup in one form and need to reuse it on posting and this two processes are independent you can create new table, write values from a from to it and analyse it on posting.

  • Suggested answer
    Sheikh Sohail Profile Picture
    6,125 on at
    RE: Can we override private method in X++

    You can not override the private method as it mentioned as private in code, but if you think that standard private method should be public then you can create Extension Request to Microsoft...

    There is an alternate way to call private method using reflection... it the provided blog works for you please mark this answer suggested.

    d365technext.blogspot.com/.../private-protected-and-public-attribute.html

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 3

#3
Willem van Duren Profile Picture

Willem van Duren 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans