How to Implement Interface in Business Central

                                       

 

With the release of Business Central Wave 1 2020 new feature was introduced called ‘Interface’. It is basically syntactical contract that can be implemented by a non-abstract method. This allows for writing code that reduces the dependency on implementation details, makes it easier to reuse code.

Today we will see how to write an interface and implement in Business central.

 Note :
With Business Central 2023 release wave 1, you can use the Go to Implementations option in the Visual Studio Code context menu (or press Ctrl+F12) on an interface to view all the implementations within scope for that interface. This is supported on interfaces, and on codeunits and enums, which implement an interface, as well as on their procedures if they map to a procedure on an interface. It's also supported on codeunit variables of type interface to jump to other implementations of that specific interface.

Snippet support :
Typing the shortcut tinterface creates the basic layout for an interface object when using the AL Language extension for Microsoft Dynamics 365 Business Central in Visual Studio Code.




If you can see in above interfaces we just define method but not programmed any business logic.

Now Lets see how to implement interface.

Added new code unit which implements the defined interface.


For checking the result of interface created following page with one function.




Below function to initialize the interface.


Lets check the result of interface.




   Let's check real-time examples like a process of sales order post.




Invoice Posting interface:




Sales post Invoice Code unit  implements Invoice Posting interface :



Let's go to the Clear buffer method and see the implementation code






Hope this will help you to understand interface and implementation.

Please let me know your views and add your questions in the comments of this article.


Thanks & Regards
Sivaramakrishna.A


Comments

Popular posts from this blog

Generate QR Code in Business Central (On-Prime) Version

Download PDF Files as Compress Zip File in Business Central

Business central Sort Variables & Sort Triggers