Quantcast
Channel: Microsoft Dynamics 365 Community
Viewing all articles
Browse latest Browse all 52382

Eventing: (Little) Update

$
0
0

In addition to my previous post http://nav-magno.be/2016/01/eventing-an-overview/ I’d like to add a few things I have forgotten in my list.

Table Trigger Parameters

In every table trigger, you might notice there is a RunTrigger boolean.

It basically states if the default trigger will be executed.

Temporary tables

Even with temporary tables the triggers will be executed!

Sample

To demonstrate the above, let’s look at this little sample:

LOCAL [EventSubscriber] HandleOnBeforeCurrencyInsert(VAR Rec : Record Currency;RunTrigger : Boolean)
MESSAGE('OnBefore %1. Temporary: %2. RunTrigger: %3',Rec.Code,Rec.ISTEMPORARY,RunTrigger);

LOCAL [EventSubscriber] HandleOnAfterCurrencyInsert(VAR Rec : Record Currency;RunTrigger : Boolean)
MESSAGE('OnAfter %1. Temporary: %2. RunTrigger: %3',Rec.Code,Rec.ISTEMPORARY,RunTrigger);

Next, I’m going to execute following code:

Currency.Code := 'EVENT1';
Currency.INSERT;

Currency.Code := 'EVENT2';
Currency.INSERT(TRUE);

CurrencyTemp.Code := 'EVENT3';
CurrencyTemp.INSERT;

CurrencyTemp.Code := 'EVENT4';
CurrencyTemp.INSERT(TRUE);

In this situation CurrencyTemp is a temporary table. This is the result:

  • OnBefore EVENT1. Temporary: No. RunTrigger: No
  • OnAfter EVENT1. Temporary: No. RunTrigger: No
  • OnBefore EVENT2. Temporary: No. RunTrigger: Yes
  • OnAfter EVENT2. Temporary: No. RunTrigger: Yes
  • OnBefore EVENT3. Temporary: Yes. RunTrigger: No
  • OnAfter EVENT3. Temporary: Yes. RunTrigger: No
  • OnBefore EVENT4. Temporary: Yes. RunTrigger: Yes
  • OnAfter EVENT4. Temporary: Yes. RunTrigger: Yes

Conclusion

Events are always fired, whether or not they are INSERT(TRUE) or INSERT(FALSE). Be sure to check what the value of RunTrigger is to see if you want the your event code to be executed.

Next to that, it brings a little bit a difficulty into the game. Where we were sure that a TRIGGER(FALSE) didn’t execute code, were not sure of that anymore!

Events are likewise triggered just the same for temporary tables. Meaning we should check our event code to see if the record isn’t temporary. Before, we had to load our record into a RecordRef and use the “IsTemporary” function. Luckily, since NAV2016, the IsTemporary is now also available directly on a table (see the code above). Next to IsTemporary, also the RecordID is now directly available on a table without having to pass a RecordRef.

Review

As you can see, the pieces of information above, about eventing, are just really, really important. That’s why I haven’t updated the previous post, but rather created a new one. To be sure all my readers still see this information. Keep this in mind when programming against events of tables!


Viewing all articles
Browse latest Browse all 52382

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>