Hi Readers,
As discussed in the Last article, in this post we will continue with our Customer Requirements.
If you are new to this series then Please Refer Table of Index.
In this article, we will discuss adding custom code in base objects and what is the Futuristic way of adding code.
In your customer are Pre-2018 then you can use Hooks for those instances.
Next Part of Requirement - "If a user changes a Quantity in Lines Expense Code in Purchase Line will be removed.".
As all we are C/AL Experts, we will try to write code to remove Expense Code when Quantity is changed in Quantity onValidate Trigger. We will write code at end of Quantity OnValidate Trigger something like as below.
How to Do that in Future?
If you lookup EventFunction - You will Trigger Event available, select onAfterValidate. Click ok to Next message and We will see that few parameters are added in function and Subscriber is added in the function Name.
Now let's lookup and Select EventPublisherElement and select the field "Location Code" as shown below.
If we look function closely - Purchase Line (Rec and XRec) variable is passed as Reference and also CurrentFieldNo so we will be able to plug our code easily as below.
To understand How Execution will occur is like this -
When System Executes Code in Purchase Line and Code will reach to line No. 622 and then execution will move to custom Codeunit and then will come back in Table 39.
Purchase Line - Line No. 622.
Codeunit 50000 - Line No. 623. (actual line No. 11)
Codeunit 50000 - Line No. 624. (actual line No. 12)
Next article, we will discuss -
Hope it makes sense, Stay Tuned for More!. Add your views as the comment to this article.
Regards,
Saurav Dhyani
www.sauravdhyani.com
As discussed in the Last article, in this post we will continue with our Customer Requirements.
If you are new to this series then Please Refer Table of Index.
In this article, we will discuss adding custom code in base objects and what is the Futuristic way of adding code.
In your customer are Pre-2018 then you can use Hooks for those instances.
Next Part of Requirement - "If a user changes a Quantity in Lines Expense Code in Purchase Line will be removed.".
As all we are C/AL Experts, we will try to write code to remove Expense Code when Quantity is changed in Quantity onValidate Trigger. We will write code at end of Quantity OnValidate Trigger something like as below.
How to Do that in Future?
- In Existing Codeunit 50000 Expense Subscriber, Let's add a new function with Name - OnAfterValidatePOLocationCode.
- Next is we will set the following properties -
- Event - Subscriber.
- EventPublisherObject - Table 39.
- EventFunction - ??
- EventPublisherElement - ??
If you lookup EventFunction - You will Trigger Event available, select onAfterValidate. Click ok to Next message and We will see that few parameters are added in function and Subscriber is added in the function Name.
Now let's lookup and Select EventPublisherElement and select the field "Location Code" as shown below.
If we look function closely - Purchase Line (Rec and XRec) variable is passed as Reference and also CurrentFieldNo so we will be able to plug our code easily as below.
To understand How Execution will occur is like this -
When System Executes Code in Purchase Line and Code will reach to line No. 622 and then execution will move to custom Codeunit and then will come back in Table 39.
Purchase Line - Line No. 622.
Codeunit 50000 - Line No. 623. (actual line No. 11)
Codeunit 50000 - Line No. 624. (actual line No. 12)
Next article, we will discuss -
- What we did in this article?
- What is Trigger Event?
- Who can write it and how it executes?
Hope it makes sense, Stay Tuned for More!. Add your views as the comment to this article.
Regards,
Saurav Dhyani
www.sauravdhyani.com
Comments
Post a Comment