microsoft / AL

Home of the Dynamics 365 Business Central AL Language extension for Visual Studio Code. Used to track issues regarding the latest version of the AL compiler and developer tools available in the Visual Studio Code Marketplace or as part of the AL Developer Preview builds for Dynamics 365 Business Central.
MIT License
732 stars 243 forks source link

.istemporary does not work in subscribers #5944

Closed bpiechowicz closed 4 years ago

bpiechowicz commented 4 years ago

Describe the bug

.istemporary always returns 'No' in subscribers. Please suggest a workaround if the bug is to be fixed in future versions.

To Reproduce

Run the below procedure 'CreateItemCategoryTemp':

procedure CreateItemCategoryTemp()
var
    ItemCatTemp: Record "Item Category" temporary;
begin
    ItemCatTemp.Init();
    ItemCatTemp.Code := 'test';
    ItemCatTemp.Insert();
    Message(Format(ItemCatTemp.IsTemporary));
end;

[EventSubscriber(ObjectType::Table, Database::"Item Category", 'OnAfterInsertEvent', '', true, true)]
local procedure OnAfterInsertItemCategory(Rec: Record "Item Category")
begin
    Message(Format(rec.IsTemporary));
    if Rec.IsTemporary then
        exit;
    DoSomething(Rec);
end;

As the result, 'DoSomething' procedure is ALWAYS executed, regardless the record being temporary or not. The code above gives messages 'No', 'Yes'.

Expected behavior When the record is temporary the .istemporary in subscriber should return 'Yes'.

Screenshots image First message: image Second message: image

5. Versions:

dzzzb commented 4 years ago

I think you need to receive (i.e. the publisher needs to pass) the record by var. Temporariness doesn't propagate through by-value record arguments in any case, AFAIK.

bpiechowicz commented 4 years ago

You are right, that helped, thanks a lot!