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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Code doesn't not working in Extension

(0) ShareShare
ReportReport
Posted on by 972
Hi All
I am facing an issue when developing a new function for client.
In D365, there are two classes "EInvoiceJourBaseMap_MX" and "CustInvoiceJourEInvoiceJourMap_MX" (CustInvoiceJourEInvoiceJourMap_MX extends EInvoiceJourBaseMap_MX).
So I follow standard way to add a method to Extension of EInvoiceJourBaseMap_MX like below
And also add real logic to Extension of CustInvoiceJourEInvoiceJourMap_MX like below.
 
However, when I run the code, it never goes to real logic under CustInvoiceJourEInvoiceJourMap_MX. Please advise.
Thank you!
Categories:
I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at
    Moved from Integration, Dataverse, and general topics forum to Finance | Project Operations, Human Resources, AX, GP, SL forum.
     
    You've created two independent methods (there is no inheritance of extensions) and which method will be used depends on the type of the variable where you call it. I guess you have an EInvoiceJourBaseMap_MX variable containing CustInvoiceJourEInvoiceJourMap_MX object and you incorrectly believe that polymorphism will kick in and call SAS_MX_BelongtoV1_R2() of CustInvoiceJourEInvoiceJourMap_MX. despite you calling SAS_MX_BelongtoV1_R2() of EInvoiceJourBaseMap_MX. It's not the case.
  • Anton Venter Profile Picture
    20,656 Super User 2026 Season 1 on at
     
    In addition to what Martin wrote, can you show us some debugging screenshots of what's happening in code? I can see that you added a new method to the base class and implemented some logic in the child class. How is this new method called? Can you show us the object type? Is it EInvoiceJourBaseMap_MX or CustInvoiceJourEInvoiceJourMap_MX? I'm guessing it's EInvoiceJourBaseMap_MX.
  • JustZM Profile Picture
    972 on at
    Thank you for your answer. I am calling this method from create_ForeignTradeElement() (Extension of EInvoiceXMLFormat_V3_3_MX). In "EInvoiceXMLFormat_V3_3_MX", eInvoiceJourMap is CustInvoiceJourEInvoiceJourMap_MX.
    When it is calling "isForeignTrade", it will goes to "SAS_MX_CustInvoiceJourEInvoiceJourMap_MX_Extension"
     
    Please advise.
    Thank you!
     
     
  • Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at
    As I explained above, it doesn't work as you think. It's irrelevant that eInvoiceJourMap variable contains an CustInvoiceJourEInvoiceJourMap_MX object. It's declared as EInvoiceJourBaseMap_MX and the extension of EInvoiceJourBaseMap_MX will be used, regardless of what code you have in the extension of CustInvoiceJourEInvoiceJourMap_MX.
     
    isForeignTrade() is a complete different scenario, because it's not extension. Extensions don't work the same way.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 658

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 468 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 333 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans