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
744 stars 245 forks source link

AA0214 - The record XXX should be modified before saving to the database (calling record method that updates fields). #6382

Closed salgiza closed 2 years ago

salgiza commented 3 years ago

Describe the bug I think I've found an additional situation in which the AA0214 rule fails. I've got some code that gets a record, calls a method (defined in the table) that updates some fields, and then calls Modify() on the record. The AL analyzer complains that the record has not been modified before saving to the database.

To Reproduce Create a table with an integer field called TestField, and add a procedure that updates the field.

procedure UpdateField()
begin
    TestField := 1;
end;

Now create a procedure, that gets the record, and calls the method:

procedure TestAnalyzer()
var
    TestRecord: Record "Test Record";
begin
    if TestRecord.Get() then begin
        TestRecord.UpdateField();
        TestRecord.Modify();
    end;

(There is no need to actually run the code as this is an analyzer bug).

Expected behavior No warning should be raised.

Screenshots I'm including some screenshots of the real code where this warning was raised.

image

image

image

Note that the table method has all field assignments inside case statements, just in case I'm mistaken and the error is not so much due to the method being in the table as it is because of a combination of that and the field assignment being within a case statement.

5. Versions:

mazhelez commented 2 years ago

Thanks for reporting this issue. Sorry we haven’t completed it yet, but we’ve had to prioritize elsewhere. We’re planning to give the CodeCop engine and its rules an overhaul in a future major release. Thanks for your patience.

Going forward we will not track progress on CodeCop issues here on GitHub. Hence, we are closing this issue.