When creating functions we sometimes need a lot of parameters to give the information we require. Number of arguments/parameters to function have limits.
Sometimes these parameters are optional, only required in some scenarios.
This makes calling them quite hard. The code becomes hard to read & understand, and sometimes spread across multiple lines.
When changing the signature of any std. function or already implemented functionality which is highly used over the system in several objects you might end up changing an endless chain of objects.
Imaging adding a field to such function, or change a datatype. The amount of code affected is pretty big and if you need to parameter only for one specific case you end up changing a lot of code for no purpose. Does this make sense?
These challenges can be solved by grouping commonly used arguments in a single table and use that table as the parameter of a function.
So the solution is to create a single table that holds the contract for the function.
When we add new fields to the table, we effectively do not change the signature of the function hence this acts as overloading allowing optional parameters to change the behavior of the code.
You can find usage of such Argument Tables in below objects:
Type ID Name
1 9500 Email Item
5 260 Document-Mailing
5 9520 Mail Management
Table is created to hold Parameter Values which will be passed to the function.
This Function in Table Pass the record as a parameter to the function, basically this is passing 10 Parameters using single record as a Parameter to the Function.
In Codeunit Document-Mailing below function, This is the extra work which you will be required to perform, if you miss this part you may not get errors at compile time but all the 10 Parameters will be passed as blank. This may be counted as side-effect of using such concept.
In Codeunit Mail Management below function, This Pass the record as a parameter to the function, basically this is passing 10 Parameters using single record as a Parameter to the Function.
In Codeunit Mail Management below function, This receives the record as a parameter to the function, basically this is receiving 10 Parameters using single record as a Parameter to the Function.
Best part is Argument tables can be outside of a customer’s license file since we never insert data in the SQL Server database.
For more details you can see this Link. https://community.dynamics.com/nav/w/designpatterns/245.argument-table
No comments:
Post a Comment