AL icon indicating copy to clipboard operation
AL copied to clipboard

AA0214 - The record XXX should be modified before saving to the database.

Open fvet opened this issue 6 years ago • 19 comments

Not sure about what warning AA0214 means. I've this part of code, resulting in error AA0214. What's wrong with this function?


 local procedure ProcessMessage(precMessage: Record "NVT b-Alert Read Message")
    var
        lrecObcIntegration: Record "NVT OBC Integration";
        ldatPrevMessage: DateTime;
    begin
        //     Processes a b-Alert message and imports it into the OBC integration table

        ldatPrevMessage := 0DT;

        lrecObcIntegration.Reset;
        lrecObcIntegration.SetCurrentkey(Trailer, "From DateTime");
        lrecObcIntegration.SetRange(Trailer, precMessage.Trailer);
        lrecObcIntegration.SetRange(Vehicle, '');
        if lrecObcIntegration.FindLast then begin
            if lrecObcIntegration."From DateTime" < precMessage."Time Stamp" then begin
                ldatPrevMessage := lrecObcIntegration."From DateTime";
                lrecObcIntegration.Validate("To DateTime", precMessage."Time Stamp");
                lrecObcIntegration.Modify;
            end
        end;

image

fvet avatar Feb 13 '20 16:02 fvet

I also have this warning in procedures without Insert/Modify/Delete/Rename: these procedures are just reading the database. Quite strange...

nicolassaleron avatar Feb 13 '20 20:02 nicolassaleron

Same for me, even in the newest AL Language extension (5.0.232930) this warning occurs. Sometimes twice for the same variable.

DBiernat avatar Feb 14 '20 11:02 DBiernat

I have disabled AA0214 for now. I like the idea, but the current implementation is broken. I checked about 100 AA0214 warnings a not a single one of them was anything to warn about.

AskeHolst avatar Feb 14 '20 20:02 AskeHolst

@MarcHansenMicrosoft

atoader avatar Feb 21 '20 19:02 atoader

same here: image

The record Customer should be modified before saving to the database.AL(AA0214) But I'm only reading it, not modifying. P.S. sorry the useless code

f4n0 avatar Feb 24 '20 11:02 f4n0

Also merely using a function with a var parameter triggers a warning. Independent of its contents.

image

If this can't be fixed it would be practical to be able to individually ignore the "var" check, not lose to the other (then fixed) functionality as well while ignoring AA0214.

Random-PasserBy avatar Feb 28 '20 18:02 Random-PasserBy

Not just reading, even when the local variable is modified, it still tells me to modify it (before you hiss at me I am not actually inserting Location records :), I've modified the code here to prevent publishing client sensitive information) image

I even get the error twice: image

I don't get the message to begin with, what are you trying to catch here? I have like 50 instances of this error in a very small app and I don't see anything wrong with any of the code.

TheDenSter avatar Mar 31 '20 00:03 TheDenSter

Nice variant here: Four copies (On the two variable definitions) of:

The record Field should be modified before saving to the database. 
The record TempField should be modified before saving to the database. 

A Filtered list of the 'Field' table is copied to 'TempField' and then "processed".

rdebath avatar Apr 01 '20 14:04 rdebath

You can add line in settings.json "al.ruleSetPath": "_BC.ruleset.json"

An put this _BC.ruleset.json in root directory to ignore this warnings. This will not help solving the bug of course, and the risk is you can forget them once bug is solved image

stijn9830 avatar Apr 02 '20 11:04 stijn9830

The record Rec2 should be modified before saving to the database.AL(AA0214)

Here is another one.

My I suggest running these rules on the base code before releasing them.

        trigger OnValidate()
        var
            Rec2: Record "ITF Template Setup";
        begin
            Rec2.SetRange(Usage, Rec.Usage);
            if Rec2.FindFirst() then
                Error(OnlyOneTxt, Rec2.Name);
        end;

JSebastianN avatar Apr 07 '20 21:04 JSebastianN

Rule should be junked.

My ruleset.json has been growing exponentially with every update

mjmatthiesen avatar Apr 07 '20 21:04 mjmatthiesen

The fix in latest master branch version.

MarcHansenMicrosoft avatar Jun 30 '20 09:06 MarcHansenMicrosoft

The fix in latest master branch version.

What exactly did you change? Just deleted the rule? Btw, is the master branch available for public? This repo's master branch was updated in february ;)

AndyF2k25 avatar Jun 30 '20 12:06 AndyF2k25

@AndreasGloeckner You cannot use the published repo code for testing, but you must pull the latest bc insider docker container (bcsandbox-master). Only this docker container contains the latest VSIX version.

NKarolak avatar Jun 30 '20 12:06 NKarolak

@AndreasGloeckner You cannot use the published repo code for testing, but you must pull the latest bc insider docker container (bcsandbox-master). Only this docker container contains the latest VSIX version.

Didn't want to use it for testing, just wanted to have a look in the source ;) But thanks for your feedback.

AndyF2k25 avatar Jun 30 '20 13:06 AndyF2k25

We did not removed the rule. The rules had issues detecting the proper use of a variable this has been improved.

MarcHansenMicrosoft avatar Jun 30 '20 13:06 MarcHansenMicrosoft

The reports of this issue being fixed have been greatly exaggerated. This is still an issue.

This code… “ procedure ShowAssemblyRecords(OrderRequisition: Record "WC GAP07 Order Requisition") var AssemblyHeader: Record "Assembly Header"; PageManagement: Codeunit "Page Management"; RecordRef: RecordRef; begin with OrderRequisition do begin Clear(AssemblyHeader); AssemblyHeader.SetRange("WC GAP07 Ord. Req. No.", "No."); if AssemblyHeader.IsEmpty then exit; AssemblyHeader.FindFirst(); RecordRef.GetTable(AssemblyHeader); ” Resulted in this error message… The record AssemblyHeader should be modified before saving to the database. { "resource": "/c:/Repo/Bioworld/GAP07-Contract Print and Kit Types/src/codeunit/WCGAP07CreateAOs.Codeunit.al", "owner": "generated_diagnostic_collection_name#0", "code": "AA0214", "severity": 4, "message": "The record AssemblyHeader should be modified before saving to the database.", "source": "AL", "startLineNumber": 99, "startColumn": 9, "endLineNumber": 99, "endColumn": 23 }

Only when I comment out the AssemblyHeader.SetRange("WC GAP07 Ord. Req. No.", "No."); does the error go away.

ElmarFV avatar Aug 27 '20 12:08 ElmarFV

@ElmarFV I would recommend disabling that warning. It's not actually useful to begin with imo. Also, you are identifying your client with the resource folder.

if AssemblyHeader.IsEmpty then exit; AssemblyHeader.FindFirst();

Personally I would simplify this to if not AssemblyHeader.FindFirst() then exit; Though I don't know what optimizations BC does under the hood for each statement, or what caching, so realistically, it may not matter.

mjmatthiesen avatar Aug 27 '20 15:08 mjmatthiesen

If you have a more specific bug that hasn't been fixed, open a new issue for it, or it won't be.

Agreed that if not FindFirst() makes more sense. Also, the Clear() is totally redundant, since being a new local variable that hasn't been used yet, it's already clear by definition. We only 'needed' that kind of paranoid clear/reset rain-dance when all variables were global as folk were too lazy to make them local, but there's no excuse for that now IMO.

dzzzb avatar Aug 27 '20 15:08 dzzzb