Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

override private method in class extension x++

(0) ShareShare
ReportReport
Posted on by 163

There is any way to override private method in class extension ? 

I made a class extension and I want to override method but its private method , How Can I access it ?

  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: override private method in class extension x++

    Hi Menna, Thanks for pointing out I didn't checked that method, you need duplicate this method as well then. This is the downside of bypassing a private method, lot of standard code has to be duplicated and that's why not a recommended approach.

  • Menna Allah Ahmed Profile Picture
    Menna Allah Ahmed 163 on at
    RE: override private method in class extension x++

    Hi Mohit , Thanks for your replying but I want to ask you a question , when I opened InventJournalTableJumpRefHelper class the menuItemName() method called in jumpref() method not in main method so How Can I Change it in main() method , In getmenuItemName(tableBuffer) method I want to change logic in it change returned name from it not parameter . Can you explain it ?

    Screenshot-_2800_40_2900_.pngScreenshot-_2800_39_29005F00_LI.jpg

  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: override private method in class extension x++

    Hi Menna, You can create a copy of main method of InventJournalTableJumpRefHelper class and rename and replace menuItem name in getMenuItemName method's parameter.

    Create extension class of InventTransRefId field in ITMOverUnderTransLine datasource in  ITMOverUnderTrans form. For reference you can check below thread

    community.dynamics.com/.../extension-class-of-form-datasource-field-method

    Create Coc method for JumpRef and before 'next JumpRef'  change ITMOverUnderDocType to any other value so it will bypass standard jumpRef code later. Copy jumpRef code in your method and replace call to Main method with your new method.

    Please note that its not an ideal approach and not recommended by Microsoft as it will require to bypass standard method and creating your own methods. So, in future if MS releases any update to these objects, your customizations will impact.

  • Menna Allah Ahmed Profile Picture
    Menna Allah Ahmed 163 on at
    RE: override private method in class extension x++

    Hi Mohit , My requirement is to change the menu item name that called in jump ref method , but menu item name () is a private method in  InventJournalTableJumpRefHelper class so to change that I wrote a new  public method in class extension and change the menuitemname () in jump ref to my new method but class extension didn't called when I debug

  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: override private method in class extension x++

    Hi Menna, Can you please explain the requirement and which private method you are trying to override? jumpref is a public method in InventJournalTableJumpRefHelper class.

    Also you don't need to copy entire method in extension class. After 'next jumpRef' line you should add your logic and like Girish mentioned if sysmbols are loaded correctly, this method should be called.

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: override private method in class extension x++

    Does the symbol loads correctly?

    Place the debugger point inside the method and check.

    After the symbol is loaded the debugger point becomes red and it won't show any warnings.

    Thanks,

    Girish S.

  • Menna Allah Ahmed Profile Picture
    Menna Allah Ahmed 163 on at
    RE: override private method in class extension x++

    Screenshot-_2800_38_2900_.pngI tried to make new method have same logic and change what I need , but when I debug doesn't enter class extension .why ?

  • Menna Allah Ahmed Profile Picture
    Menna Allah Ahmed 163 on at
    RE: override private method in class extension x++

    How to duplicate the method , I want to change some logic in private method in class .

    I made a class extension , How to duplicate method ?

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: override private method in class extension x++

    You can duplicate the method and call that method instead of calling standard method.

    But keep in mind, in future if Microsoft release any updated on that method it won't update on your custom method.

    Thanks,

    Girish S.

  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: override private method in class extension x++

    Have you checked this thread

    community.dynamics.com/.../881069

    As Martin mentioned you can't extend private method, either raise extensibility request to Microsoft but high chances the request won't be approved easily as Microsoft made those methods private for reason.

    FYI, we raised extensibility request few months ago, none of it is approved.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,162 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,962 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans