AL icon indicating copy to clipboard operation
AL copied to clipboard

Use IF Statement in Subscribed Event

Open ashishsharmanav opened this issue 8 years ago • 4 comments

I have a developed solution wherein on codeunit 12 there is function getting executed in base code (Nav 2018 CU5) which has been made to be executed conditionally by putting an IF condition just above the base code. I don't want to write the If statement on the base code hence i tried to publish an event and subscribe the same in VS Code in a new codeunit. Now how am i supposed to handle the response as events doesn't support return type.

Anyone please help !!

ashishsharmanav avatar Jul 03 '18 14:07 ashishsharmanav

Seems you need to request an event with a handled pattern. See this example, just with IF Handled THEN BEGIN END instead of IF Handled THEN EXIT.

NKarolak avatar Jul 04 '18 06:07 NKarolak

@NKarolak - Thanks for the reply. In this case i will end up modifying the base code in nav . It seems like something like this :

"**>>>>> New Code BEGIN OnBeforeReCalc(Rec,_Message,Handled); IF Handled THEN EXIT;

New Code END**"

need to be created and then requested to microsoft to be published in next version. Please correct me if i am wrong with the understanding.

ashishsharmanav avatar Jul 04 '18 06:07 ashishsharmanav

If you want to leave the whole function where OnBeforeReCalc is called, then the EXIT is fine. If you wanted to skip only what is called directly after OnBeforeReCalc and execute the other code lines after, then you'd need to adjust your request.

However, to finish to request, you have to mention which standard object and function is affected, and where exactly to put your code in.

Microsoft would implement the code change in the fall release, and in the pre-releases of D365BC. If you need it in the next NAV cumulative update(s), then you'd need to create a NAV support request instead. GitHub serves you only for D365BC.

NKarolak avatar Jul 04 '18 06:07 NKarolak

@NKarolak - Thanks, this one solves my query. 👍

ashishsharmanav avatar Jul 04 '18 06:07 ashishsharmanav