Skip to main content

With Statement Deprecation in Business Central.

Hi Readers,

The "with statement deprecation in Business Central" is a significant change that developers need to address. Microsoft's decision to remove support for this statement has far-reaching implications for AL development and upgrade projects. Let's explore what this means for Business Central developers and how to prepare for this important transition.


Understanding the With Statement in Business Central AL Development


The with statement has been a part of Business Central (formerly Dynamics NAV) for years. It allowed developers to write more concise code by implicitly referencing fields and functions of a record or table. However, Microsoft announced its deprecation due to known issues and potential performance problems.

There are two types of with statements:

  • Implicit with statements: These don't explicitly declare the record or table being referenced.
  • Explicit with statements: These clearly state the record or table in use.


Both types will soon be unsupported in cloud development, with warnings eventually becoming errors.


Microsoft's Solution for Converting with Statements in Business Central


To help developers transition away from with statements, Microsoft has introduced an extended code action feature. This new tool offers three options for converting with statements:

  1. Convert in the current document
  2. Convert in the entire project
  3. Convert in the workspace

This feature is a significant improvement over previous solutions, which only allowed conversions on a per-method or per-file basis.


Preparing for Business Central Upgrades: Addressing with Statements


For upgrade projects, addressing with statements is particularly important. When legacy code is converted to AL extensions, with statements remain intact. This can result in hundreds of instances that need correction.

To use the new code action feature:

  1. Locate a with statement in your code
  2. Click on the yellow button next to it
  3. Choose your desired conversion scope (document, project, or workspace)
  4. The tool will automatically convert the statements to fully qualified references

Best Practices for AL Extension Code Without with Statements


Moving away from with statements offers several benefits:

  • Improved code readability
  • Better performance in many cases
  • Reduced likelihood of errors due to ambiguous references

When rewriting your code, focus on using fully qualified statements. This means explicitly referencing the record or table for each field or function call.


Updating Your VS Code AL Extension for With Statement Conversion


To access the new code action feature, you'll need to update your AL extension in Visual Studio Code. Here's how:

  1. Check your current AL extension version
  2. If it's below version 14.0.11, update to the pre-release version
  3. Once version 14.0.11 or higher becomes the release version, you can switch back from the pre-release

This update is crucial for efficiently converting with statements in your projects.


The Future of Business Central Development


The removal of with statements is part of Microsoft's ongoing efforts to improve Business Central's performance and reliability. As developers, it's our responsibility to adapt to these changes and optimize our code accordingly.

By embracing these new tools and practices, we can create more robust and efficient AL extensions. This not only benefits our current projects but also prepares us for future advancements in Business Central development.

FAQ (Frequently Asked Questions)


Why is Microsoft deprecating the with statement in Business Central?


Microsoft is removing support for with statements due to known issues they can cause, including potential performance problems and code ambiguity. This decision aims to improve the overall reliability and efficiency of Business Central applications.

When will the with statement become an error instead of a warning?


While an exact date hasn't been announced, Microsoft has indicated that the transition from warning to error will happen in a future release. It's advisable for developers to start converting their code now to avoid future complications.

How can I convert with statements in my existing AL code?


Microsoft has introduced an extended code action feature in the AL extension for Visual Studio Code. This tool allows you to convert with statements in the current document, the entire project, or across your workspace. To use it, ensure you have the latest version of the AL extension installed.

Will removing with statements improve my code's performance?


In many cases, yes. Fully qualified statements can lead to better performance as they eliminate the overhead of implicit references. Additionally, they improve code readability and reduce the likelihood of errors due to ambiguous references.

How do I update my VS Code AL extension to access the new conversion feature?


Check your current AL extension version in VS Code. If it's below version 14.0.11, update to the pre-release version. Once version 14.0.11 or higher becomes the standard release, you can switch back from the pre-release version.


Regards,
Saurav Dhyani

https://bit.ly/SubscribeSauravYouTube 

Comments

Popular posts from this blog

VIEW SERVER STATE permission on SQL Server?

Hi all, Sometime While trying to Login into a database we face an error message as shown below. --------------------------- Microsoft Dynamics NAV Classic --------------------------- You cannot start Microsoft Dynamics NAV Classic because you do not have the VIEW SERVER STATE permission on SQL Server. Contact your system administrator. --------------------------- OK    ---------------------------

NAV 2013 R2 - Cumulative update 12 Released.

Hi all, Please find below the details of  Cumulative Update 12 released for Microsoft Dynamics NAV 2013 R2. Title - Cumulative Update 12 for Microsoft Dynamics NAV 2013 R2 Build No. - 38053 Release Date - October, 2014 Local Version Included - AU, AT, BE, CH, DE, DK, ES, FI, FR, IS, IT, NA, NL, NO, NZ, SE, UK, RU Download Link Note: Implementing this cumulative update will require a database conversion unless you have already implemented update rollup 5.

Error After Restore SQL Backup of NAV 2013 Database

Hi all, we are facing a conman issue during restoring a SQL Database backup restored for NAV 2013. While Trying to run object from Object Designer we get below listed error (even the service is configured properly) - --------------------------- Microsoft Dynamics NAV Development Environment --------------------------- There are no NAV Server instances available for this database. You must ensure that a NAV Server instance is running and is configured to use the database before you perform this activity. --------------------------- OK    ---------------------------