Skip to content

AA0214 - warning AA0214: The record ... should be modified before saving to the database. #5508

@gregoral

Description

@gregoral

Describe the bug
I used Microsoft Example AL code for SetTable method.

I added two lines to change a field value and call modify.
CodeAnalyzer gives the following warning:
warning AA0214: The record ProdOrderComp should be modified before saving to the database.

NOTE: the MS example code has issues by itself ( variable ordering, GETRECORD, missing parenthesis ). For clarity I fixed the issues that give warnings in the provided example code.

To Reproduce:
Compile the code in any AL extension.

AL Code to reproduce the issue:

codeunit 50000 "TEST"
{
    // warning AA0214: The record ProdOrderComp should be modified before saving to the database.

    procedure TEST()
    var
        InvtEventBuf: Record "Inventory Event Buffer";
        ProdOrderComp: Record "Prod. Order Component";
        RecID: RecordId;
        RecRef: RecordRef;
    begin
        InvtEventBuf.FIND('-');
        RecID := InvtEventBuf."Source Line ID";
        RecRef := RecID.GETRECORD();
        RecRef.SETTABLE(ProdOrderComp);

        // this two lines trigger the warning
        ProdOrderComp."Due Date" := 0D;
        ProdOrderComp.Modify();
    end;
}

Expected behavior
a) if the example code properly uses RecordRef methods, there should be no warning
b) if the example code has a problem, the example should show how that should be done

5. Versions:

  • AL Language: 5.0.199157
  • AL Compiler version: 5.0.3.2555
  • docker image: bcinsider.azurecr.io/bcsandbox-master:16.0.10516.0-w1-ltsc2016

Additional test code:

codeunit 50000 "TEST"
{
    // warning AA0214: The record ProdOrderComp should be modified before saving to the database.

    procedure TestAA0214_1()
    var
        InvtEventBuf: Record "Inventory Event Buffer";
        ProdOrderComp: Record "Prod. Order Component";
        RecID: RecordId;
        RecRef: RecordRef;
    begin
        InvtEventBuf.FIND('-');
        RecID := InvtEventBuf."Source Line ID";
        RecRef := RecID.GETRECORD();
        RecRef.SETTABLE(ProdOrderComp);

        // this two lines trigger the warning
        ProdOrderComp."Due Date" := 0D;
        ProdOrderComp.Modify();
    end;

    procedure TestAA0214_2()
    var
        StandardText: Record "Standard Text";
    begin
        StandardText.Init();
        StandardText.Code := 'Test';
        StandardText.Insert();

        // this two lines trigger the warning
        StandardText.Description := 'Test';
        StandardText.Modify();
    end;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions