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 :
Microsoft Dynamics AX (Archived)

Microsoft Dynamics AX (AX 7) - Class Extension

(0) ShareShare
ReportReport
Posted on by 1,920

Hi guys,

In AX 7 we can extend Tables and Forms to avoid customization in base objects. Is the same possible in Classes ? The reason is, I have separate package where I am extending base Tables and Forms for customization. But I can't do the same in Classes. I want to make my package independent of base package and that's the goal of it. 

Also is there any possibility I can refer the base Classes from my own package. Say I want to access the "ReqCalc" class and to do some customization in the class in my own package.

Yes, It is possible to go with over-layering (for classes) and it needs the base package to be used. But to go with my own package how to do it. 

Please help me, Thanks in advance. 

*This post is locked for comments

I have the same question (0)
  • Sohaib Cheema Profile Picture
    49,438 User Group Leader on at
    • Yes, you can extend classes also. Extended methods of a class must be static. You can find many examples on Google. if you are unable to find, tell us so we can show you.

    • As you have already choose approach of “extension” you cannot customize any object. If you have to customize, make sure to choose existing package approach while you will create a new model. Your solution can contain multiple projects, one might be using extensions only and other might be using only customizations.

       

      It is not possible to develop a solution 100% free of OverLayring, as of today.

  • Martin Dráb Profile Picture
    237,892 Most Valuable Professional on at

    First of all, don't forget that X++ is an object-oriented language, therefore you can create specialized classes by leveraging inheritance and polymorphism.

    Sometimes it's enough to create a subtype and use in your code. Sometimes you need standard code to use your subtype, so the standard code must allow you to inject it in some way, namely through dependency injection or plugins.

    AX 7 also offers extensions methods, mentioned by Sohaib. They're static methods in a different class that can be called in a in the same way as instance method added to the extended class. (But they're still static methods in a different class, they can't access private fields and methods.)

    And more important tool for this scenario is events.

  • Mohamed Meeran Profile Picture
    1,920 on at

    Thanks Sohiab and Martin. I agreed with inheritance and polymorphism, if there are new methods to be used. But in my scenario I have customized an "if" section in a method in a standard class.  

    The reason I am asking is, I want to go with independent deployable package of my own  not along with base package.

  • Suggested answer
    Martin Dráb Profile Picture
    237,892 Most Valuable Professional on at

    But you can't do such a thing by table and form extensions either. You need a customization if you want to change code inside a method.

    That you have to make a customization doesn't mean that you have to put all code into the standard package - you can only add an extension point and extend it in your custom package.

  • Mohamed Meeran Profile Picture
    1,920 on at

    Thanks guys. I gone through the Event part in AX 7 through Fleet Management. In Fleet management they have accessed the base class through event handlers.

  • Martin Dráb Profile Picture
    237,892 Most Valuable Professional on at

    If you problem is resolved, please mark the question as resolved. If not, please explain what you need from us.

    Events are very important; that's why I mentioned them above. They allow you to extend the application, but not to customize an "if" section in a method in a standard class, as you required. Maybe it means that you've found that you actually don't need the customization and you can design your logic as an extension.

  • Community Member Profile Picture
    on at

    I've seen a lot of suggestions customizing a standard class and so on. E.g. in the latest versions it's not possible anymore modify standard classes. In model management you can't even add reference to your package for getting it working.

    I came across a problem where I have a class in separate package which extends the standard class and overrides it's protected method. This overridden method is never executed when running the code. Events don't work for protected methods. I don't know how it's possible extend standard code in separate packages, especially with protected methods.

  • Martin Dráb Profile Picture
    237,892 Most Valuable Professional on at

    You must understand the difference between customizations (overlayering) and extensions.

    Customizations are still possible, but it means that your module must be insider the same package. If you must use a separate package, you're limited to extensions; you can't make customizations.

    If you create a new class inheriting from a standard class, you can't expect that standard code will magically start using your new class. It has no idea about it. You would have to give it an instance of your class instead of an instance of the standard class. It's not new in AX 7.

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans