Interface in Business Central AL – Sample:
Hello Readers,
I was wondering how interface works with the Business Central, I did a small coding to check, how exactly it works.
Benefit’s of using Interface:
1. This allows for writing code that reduces the dependency on
implementation details.
2. This makes it easier to reuse codes.
3. It supports a
polymorphic way of calling object methods, which again can be used for
substituting business logic.
P.S.: The methods defined in the interface needs to be implemented, this only invokes single codeunit and this also can be used in events.
In the below example i have create a interface with for get the Item Inventory of the selected record in the item list.
Steps:
1. Create a new .al file for Interface ( this does not require Object ID)
2. Now create a new .al codeunit file and call your interface created in the step 1.
Add the same Procedure name as mention in the interface. – (in my case ItemInventory)
3. Now, lets create a item list extension page and create a new action to check the output.
call the local procedure and pass the interface as a parameter.
>> Before that, we need to initialize the interface, otherwise it will give error message that interface has not been initialized.
>> To initialize add the local procedure with interface type parameter and call the procedure defined in the interface.
below is the output:
I’ll explore more on it and write some more content further to this.
Thank you,
Anish Agrawal
Business Central / NAV Developer
Phone No. +91-9770757595
LinkedIn : https://www.linkedin.com/in/anish-agrawal-41953377/
Good Information