Quick fix for warning AL0604: Use of implicit ‘with’ will be removed in the future.

If you have not read my previous blog posts about the Implicit WITH, I suggest you read them to get a better understanding of the Implicit WITH. Also, you can read the Microsoft Docs to get more information as well.

If you are getting hundreds of warning like below and would want to fix all of them in a one go?

warning AL0604: Use of implicit 'with' will be removed in the future.

You can install “AL CodeAction” extension into the VS Code which will give you a super fast way to resolve all the hundreds of warnings related to implicit WITH statement.

If you read the release note carefully you will note there are some very important information in there.

If a file contains more than 100 warnings then not all usages are reported by the AL Language extension. In these cases, please execute the command a second time after the warnings are recalculated (reload window?). 

Once the installation is complete, compile the extension. Then press F1 and select “AL Code Actions: Fix Implicit with usage”. This will fix all your errors and if you still see some of the warnings recompile the code and follow the same steps.

Now you will not have any warnings or errors regarding the implicit WITH, but what you need to do is make sure everyone else follows the same in the future. In order to do that you have 2 options. The first option was discussed in my previous blog post. Which is adding NoImplicitWith as features to the app.json file.

The second option is to add a pragma is an instruction to the compiler on how it should understand the code. The pragma instructs the compiler not to create an implicit with for the variable. (Read more about pragma)

The following shows the syntax for the implicit with pragma. The pragma must be used before the beginning of the codeunit or page.

#pragma implicitwith disable

You do not have to go to each file and add the above the line of code. You can simply run below command in your VS Code which will do that job for you.

If your check your changes you will notice that all your codeunits and pages are been changed. First line of the each codeunit and page will have below code line

#pragma implicitwith disable

Last line of the codeunit and page would have below

#pragma implicitwith restore

Please provide your feedback with a comment. 
Thank you and Regards,
Tharanga Chandrasekara

Click on a star to rate it!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.