Skip to main content

Notifications

Announcements

No record found.

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

New line of code in middle of a method through extension in d365fo

Posted on by 297
Hello, 
I will need to be able to call a parm method on a contract class which falls in the middle of the method (Form method) and this Contract class is then supplied to another class.
Functionality is there are 2 custom fields on a worker. 
Is this even feasible?
Thanks
  • Layan Jwei Profile Picture
    Layan Jwei 7,347 Super User 2024 Season 2 on at
    New line of code in middle of a method through extension in d365fo
    Hi SKO,

    can you please provide more details? maybe share with us the code and let us know what you exactly want to do. it will be easier for us to imagine the scenario

    Thanks,
    Layan Jweihan
  • Suggested answer
    Kevin Xia Profile Picture
    Kevin Xia Microsoft Employee on at
    New line of code in middle of a method through extension in d365fo
    Hi,
    it is feasible to insert new lines of code in the middle of a method using extension techniques. Specifically, you can achieve this through the use of method wrapping in extension classes. Here's a general approach:
    Create an Extension Class:
    • Create an extension class for the target class where you want to insert code.
    • In the extension class, create a new method or use an existing one to add your custom logic.
    Use Chain of Command:
    • Use the chain of command framework to wrap the method you want to extend.
    • Inside the wrapper method, call the original method using next and then insert your custom code before or after the original call.
    Call a Parm Method:
    • If your contract class has a parameter method (parm method), you can call it within your custom logic.
    Supply Contract Class:
    • After adding your custom code, you can then supply the modified contract class to another class or method.
    Best regards,
    Kevin

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans