Skip to main content

Notifications

Announcements

No record found.

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

  • Suggested answer
    Sheikh Sohail Profile Picture
    Sheikh Sohail 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

  • Mea_ Profile Picture
    Mea_ 60,278 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.

  • Dhanshri Profile Picture
    Dhanshri 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.

  • Dhanshri Profile Picture
    Dhanshri 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.

  • Asim Saeed Profile Picture
    Asim Saeed 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.

  • Mea_ Profile Picture
    Mea_ 60,278 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

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey Pt 2

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,820 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,514 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans