Al: The record YYY should be modified before saving to the database.

Created on 24 Sep 2020  Â·  1Comment  Â·  Source: microsoft/AL

Describe the bug
As with #5665 I am getting a number of these errors even after it has been reported as "fixed".
I get

The record AccountingPeriod2 should be modified before saving to the database.

With this code, this is just one of many examples.

    local procedure GetPeriodEnd(PeriodStart: Date): Date;
    var
        AccountingPeriod2: Record "Accounting Period";
    begin
        with AccountingPeriod2 do begin
            SetFilter("Starting Date", '>%1', PeriodStart);
            if FindFirst() then begin
                exit(CalcDate('<-1D>', "Starting Date"));
            end else begin
                exit(CalcDate('<+CM>', PeriodStart));
            end;
        end;
    end;

A clear and concise description of what the bug is.

To Reproduce
Steps and to reproduce the behavior:
See below, just create the procedure shown

    local procedure GetPeriodEnd(PeriodStart: Date): Date;
    var
        AccountingPeriod2: Record "Accounting Period";
    begin
        with AccountingPeriod2 do begin
            SetFilter("Starting Date", '>%1', PeriodStart);
            if FindFirst() then begin
                exit(CalcDate('<-1D>', "Starting Date"));
            end else begin
                exit(CalcDate('<+CM>', PeriodStart));
            end;
        end;
    end;

Expected behavior
No warning when a record is NOT updated

Screenshots
None

5. Versions:

  • AL Language: v5.0.335750
  • Business Central: 16.5
CodeCop static-code-analysis

Most helpful comment

MS, with the greatest respect: please consider just disabling this diagnostic until it actually works. The number of legitimate cases it could catch seems dwindling compared to the number of false positives people have had to wade through across the months.

>All comments

MS, with the greatest respect: please consider just disabling this diagnostic until it actually works. The number of legitimate cases it could catch seems dwindling compared to the number of false positives people have had to wade through across the months.

Was this page helpful?
0 / 5 - 0 ratings