AL icon indicating copy to clipboard operation
AL copied to clipboard

Rec.IsTemporary gets ignored in Event Subscriber / BC Cloud

Open SaschaM-Dev opened this issue 6 months ago • 3 comments

When opening the "Sales Statistics" Page on Sales Order Page the pages runs some inserts and deletions on the corresponding Sales Lines. These Records are temporary.

On my Event Subscriber I subscribed to "OnAfterInsertEvent" and "OnAfterDeleteEvent". So far so good. However the Rec that temporary gets created and deleted ignores / does not have the attribute "IsTemporary" - hence Code will be executed that should not be executed. I've included a demo video.

"platform": "1.0.0.0",
"application": "26.0.0.0",
"runtime": "15.0"

Version: DE Business Central 26.1 (Plattform 26.0.35534.0 + Anwendung 26.1.33404.35662)

https://github.com/user-attachments/assets/52174ab5-93e5-47a1-984e-4175178bfe88

SaschaM-Dev avatar Jun 26 '25 07:06 SaschaM-Dev

This is not an issue of the AL language itself (hence your issue is in the wrong repository), but wrong code on your side. Your subscriber is missing Rec with a var parameter:

Image

Tip: When adding subscriber parameters, press Ctrl + Space to select them Image This will add the full signature including the var (as defined in the event publisher).

NKarolak avatar Jun 26 '25 08:06 NKarolak

@NKarolak thanks a lot, that worked. Interestingly it has worked before (pre v26) so there must have been some changes recently.

SaschaM-Dev avatar Jun 26 '25 08:06 SaschaM-Dev

Interestingly it has worked before (pre v26) so there must have been some changes recently.

I don't have an explanation for that. It should not have worked in any earlier version. Without the var parameter, no information about the table type could ever be passed. There is just one exception: Maybe you have remembered a subscriber for another table defined as TableType = Temporary ? Only such a table would always return IsTemporary = true.

NKarolak avatar Jun 26 '25 08:06 NKarolak

As Natalie pointed out, this should not work as is. This forum post explains the rules and how it should work: https://community.dynamics.com/blogs/post/?postid=8a992f12-76ad-46e8-9c1c-084e878e88a2

There's two ways to fix this:

  1. You should have Record "Sales Line" temporary as the parameter type (then the record gets passed by value, so you don't get what is contained in the temporary table - no finding, but you can use the values on the fields)
  2. You should have var on it, which gives you access to do finds/deletes/inserts etc., but you will be modifying the original record instance.

BazookaMusic avatar Jun 30 '25 10:06 BazookaMusic