Is there a tool/extension/script I can run for Visual Studio Code to Bulk handle errors?

263 views Asked by At

I have a rather large Dynamics 365 Business Central Extension written in AL code on Visual Studio Code platform. Microsoft is changing a rule in AL code that will result in widespread errors if not addressed before the next release. This change is that "implicit with" cannot be used, so every record reference in the code has to be qualified with "Rec.". There are several hundred places this will need to be addressed in this extension, and it is just not practical to manually adjust them one by one. For reference,

This:

                field(TradeNumber; TradeNumber)
                {
                    ApplicationArea = All;
                    Caption = 'Trade No.';
                    Editable = False;
                }
                field(TradeType; TradeType)
                {
                    ApplicationArea = All;
                    Caption = 'Trade Type';
                }

Becomes this:

                field(TradeNumber; Rec.TradeNumber)
                {
                    ApplicationArea = All;
                    Caption = 'Trade No.';
                    Editable = False;
                }
                field(TradeType; Rec.TradeType)
                {
                    ApplicationArea = All;
                    Caption = 'Trade Type';
                }

So if the error (or "problem" as it is now) is the same for these several hundred instances, is there a way to bulk-correct so to speak and just apply "Rec." to the beginning of every reference that has been flagged across the multiple files and folders?

1

There are 1 answers

0
JeffUK On BEST ANSWER

The standard AL Code extension for VS Code will include Code Actions to fix these errors. ("Qualify with Rec.")

There are 3rd party extensions available on the Visual Studio Code marketplace to fix these en-mass automatically, e.g. AL CodeActions

As you only mention Implicit, you should note that explicit WITH statements are also being 'obsoleted.' The reason for this is that the behavior of both types of 'With' statement become unpredictable when dealing with extensions; this blog post explains it in more detail.