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

Procedure Rec.GetBySystemId() doesn't find records since version 16.2 anymore #6054

Closed hharing closed 4 years ago

hharing commented 4 years ago

Describe the bug I use the SystemId to create a relation between an 'Original' record and a 'Backup' record. When I create a new record in the 'Original' table a new record is inserted with the primary key. A duplicate of this record is created in the 'Backup' table. When I enter additional information in my new record, the OnModify() trigger executes but can't find the duplicate record in the 'Backup' table when using the procedure Rec.GetBySystemId(). When I leave the newly created record, come back and do a modification, the changes are synchronized to the 'Backup' table.

To Reproduce See the print screens below and the example project.

AL Code to reproduce the issue

table 50100 "Original" { fields { field(1; "Id"; Integer) { AutoIncrement = true; }

    field(2; Name; Code[20]) { }
    field(3; Description; Text[50]) { }
}

keys
{
    key(PK; "Id")
    {
        Clustered = true;
    }
}

var
    Backup: Record Backup;

trigger OnInsert()
begin
    if Backup.GetBySystemId(SystemId) then
        exit;

    Backup.TransferFields(Rec);
    Backup.SystemId := Rec.SystemId;
    Backup.Insert(false, true);
end;

trigger OnModify()
begin
    if not Backup.GetBySystemId(SystemId) then
        exit;

    Backup.TransferFields(Rec);
    Backup.Modify();
end;

trigger OnDelete()
begin
    if not Backup.GetBySystemId(SystemId) then
        exit;

    Backup.Delete();
end;

}

table 50101 "Backup" { fields { field(1; "Id"; Integer) { AutoIncrement = true; } field(2; Name; Code[20]) { } field(3; Description; Text[50]) { } }

keys
{
    key(PK; "Id")
    {
        Clustered = true;
    }
}

}

Example project GetBySystemId.zip

Expected behavior I expect that when a new record is inserted in the 'Original' table, a duplicate record will be inserted in the 'Backup' table. I also expect that the other fields are immediately synchronized to the 'Backup' table.

Screenshots Expected behavior: afbeelding

Currently this is happening:

afbeelding

When I modify the 'Original' record, the 'Backup' record will be updated:

afbeelding

5. Versions: The GetBySystemId() functionality works in version: 16.1.12629.14241. This functionality is broken in the next versions: 16.2.13509.14411 16.3.14085.14363 16.4.14489.0

atoader commented 4 years ago

Hi! Please take a minute to read the guidelines for this repository https://github.com/microsoft/AL and our collection of frequently asked questions https://github.com/Microsoft/AL/wiki/frequently-Asked-Questions .

As this repository is only for issues related to the AL compiler in latest developer preview environment for Dynamics 365 Business Central. We suggest that you open a support case or file a bug in Collaborate, to ensure that all Business Central users benefit from your catch as soon as possible.

To open a support case, you can:

If you file the bug in Collaborate, remember to include steps to reproduce the issue, and the Business Central build number and country version you're using.