waldo: Function Overloading in AL
I haven’t been blogging much, lately. But in my defence – I put quite some time in another community project, which I blogged about in my previous post (and will blog about in quite a few coming posts…). To keep up the pace of writing at least one post each month (which I have been able to do so for the past 11 years or so) – I HAD to put something up urgently ;-). And it’s going to be about a new possibility we have in the AL language, which is often forgotten:
In C/AL we never had the ability for overloading a function. You know: using the same function name with a different context (parameters).
Now – YES WE CAN! It’s all pretty well described on docs:
How cool is that?
Can I overload more?
Overloading my own functions is nice. But the question I always get in my classes is: can we also overload functions from the default app – or from any dependent app for that matter.
Well – in short: YES WE CAN!
Let me give you a simple example:
I’m overloading the default method “CreateAndShowNewInvoice” on the vendor table with a different context (Text-parameter). So I have a completely new method, with the same name.
One thing that would be interesting is to be able to extend on a main method like that – and that’s what I basically doing above – I call the main method, and extend it with my own code.
As this works on the default app, you can expect it does work on dependent extensions as well. I created an example on my github, which you can look into.
Extension A implements a new method on the Item table (or should I say “class” ;-)):
Extension B has a dependency on A, and implements a slightly different implementation of that method. You see: same function name, different parameters
To Test the overload, I created a subscriber to logInManagement .. And you’ll see that B basically extended the implementation of A…
And yes, I hear you – One should test with a test-codeunit. So I created that for you as well :-).
And if you’re using the CRS AL Language Extension, it’s easy. Just run the C/AL Test Tool from VSCode from the command palette:
And there you go!
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
|waldo: CRS Al Language Extension||Blog bot||NAV: Blogs||0||18.04.2018 05:13|
|waldo: Enable the updated Code Analysis for AL||Blog bot||NAV: Blogs||0||26.03.2018 08:11|
|waldo: AL with VSCode: ExportToNewSyntax||Blog bot||NAV: Blogs||0||07.08.2017 04:17|
|waldo: Convert C/AL Objects to AL with PowerShell||Blog bot||NAV: Blogs||0||05.05.2017 03:33|
|CRM DE LA CREME! Some useful CRMform jscripts||Blog bot||Dynamics CRM: Blogs||0||02.09.2009 10:05|
|Опции темы||Поиск в этой теме|