Custom functions

We can also create our own custom functions to meet any need. The most common reason to create a new function is to provide a single, standardized instance of logic to perform a specific task. When we need to use the same logic in more than one place, we should consider creating a callable function.

We should also create a new function when we're modifying standard NAV processes. Whenever more than three or four lines of code are needed for the modification, we should consider creating the modification as a function. If we do that, the modification to the standard process can be limited to a call to the new function. It's usually not a good idea to embed a new function into an existing standard function. It's better to clone the existing function and make the modifications in-line in our copy.

Although using a function to insert new code into the flow is a great concept, occasionally, it may be difficult to implement in practice. For example, if we want to revise the way existing logic works, sometimes it's confusing to implement the change through just a call and an external (to the mainline process) function. In such a case, we may just settle for creating an in-line modification and doing a good job of commenting the modification. This is most reasonable, when the modification code is only required in one place and does not also need to be referenced elsewhere.

If a new function will be used in several objects, it should be housed in our library codeunit (we may choose to have multiple library codeunits for the purpose of clarity or project management). If a new function is only for use in a single object, then it can be resident in that object. This latter option also has the advantage of allowing the new function direct access to the global variables within the object being modified, if necessary.

When working with Extensions, it is not allowed to add new functions to existing objects created by Microsoft. You should always create them in your own library Codeunit objects.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.171.162