Dynamics 365 Business Central: Using AL Code Actions

Dynamics 365 Business Central

Hi, Readers.
Today I would like to talk about AL Code Actions.
The AL Language extension offers users the option to help fix issues in code. Code Actions is a Visual Studio Code feature providing the user with possible corrective actions right next to an error or warning. If actions are available, a light bulb appears next to the error or warning. When the user clicks the light bulb (or presses Ctrl+.), a list of available code actions is presented.

So, Code Actions provides possible corrective actions which will help the developer to code in a better way.

In AL Language extension these code actions are available in the current version (v7.1.453917 2021/05/12):

  • Multiple IF to CASE converting code action.
  • Spell check code action.
  • Interface implementer.
  • Make method local.
  • Use parenthesis for method call.
  • Fix explicit with statements.
  • Fix implicit with statements.

To enable AL Code Actions, open the Settings Page, navigate to Extensions > AL Language extension configuration, then click on the Enable Code Actions checkbox.

Alternatively:

Open the settings.json file, then enter the setting al.enableCodeActions and set it to true like this “al.enableCodeActions”: true.

Let’s look at a few examples.

1. Convert the ‘with’ statement to fully qualified statements.

2. Qualify with ‘Rec’ -> All occurrences in this object.

3. Fix typo.

4. Convert to ‘case of’.

Update: New AL Code Action for multiple layouts (Convert RDLCLayout/WordLayout/ExcelLayout to Rendering report session)

Update from Business Central Launch Event (2022 release wave 2) 

Update 2022.12.02: AL Code Actions

  • Fix old report layout and replace with rendering layout section
  • Fix for AW0013
  • Convert pages or page extensions to use the actionRef syntax for promoted actions on the action bar. Fix for instance, document, project, or workspace. For more information, see Code action for actions.

Add some examples:

The spell check code action is triggered on certain syntax errors:

The make method local action is triggered to fix the CodeCop Warning AA0207:

Code actions for promoted actions:

Use the code action to convert legacy syntax for promoted actions to the actionref syntax, which is introduced with Business Central 2022 release wave 2. In-client customizations, user personalization, and profile configurations are automatically converted into the new syntax, so this is primarily applicable to DEV extensions. The code action can apply to a single instance, the document, the project, or the workspace.

More details:

Note:
For Designer extensions, use F6 to open Designer, which opens the page where the legacy syntax is used. Choose the Lock symbol and use Unlock page to automatically convert the legacy syntax for the running code. Pressing Alt+F6 will bring you back into Visual Studio Code, and show the converted actionref code.

More details: Dynamics 365 Business Central: Pull designer changes into VS Code (F6 -> Design in BC -> Alt + F6)

END

Hope this will help.

Thanks for reading.

ZHU

コメント

Copied title and URL