Change multiple Application Area tags with PowerShell

Visibility of the controls in Business Central can be regulated by the ApplicationArea property. For more information, see (https://docs.microsoft.com/en-us/dynamics-nav/applicationarea-property).

Before you convert an existing Dynamics NAV solution to an extension written in AL, the ApplicationArea property must be set on all your custom controls. Otherwise, they will not be visible.

Setting the ApplicationArea property one by one is a tedious task that can be partially automated with the following PowerShell scripts:

  • Out-ApplicationAreaData [[-Path] <string>] [[-Filter] <string>] [[-ToFileName] <string>]
  • Update-ApplicationAreaData [[-Path] <string>] [[-FromFileName] <string>]

See attached zip file, which contains the NavApplicationAreaHelper.psm1 PowerShell module: NavApplicationAreaHelper

Out-ApplicationAreaData

Extracts data about controls that have the ApplicationArea property into a CSV file.

Parameters

-Path <string> 

Specifies the path to the folder,where NAV object files in TXT format are placed. By default, it is the current folder.

-Filter <string> 

Specifies the mask for filtering files of certain type. By default, it is ‘*.txt’.

-ToFileName <string> 

Specifies the name of the CSV file. By default, it is ControlsWithAppArea.csv.

Update-ApplicationAreaData

Reads the CSV file with modified controls and modifies the ApplicationArea property line in TXT objects accordingly.

Parameters

 -Path <string> 

Specifies the path to the folder, where NAV object files in TXT format are placed. By default, it is the current folder.

-FromFileName <string> 

Specifies the name of the CSV file. By default, it is ControlsWithAppArea.csv.

Procedure 

1. Run the PowerShell window and navigate to the folder where TXT objects are placed.

2. Type Out-ApplicationAreaData -Filter PAG99000*. This command creates the ControlsWithAppArea.csv file where all controls on pages starting from 99000 will be stored.

3. Using filters in MS Excel, modify values in the NewApplicationArea column and then save the file as a CSV UTF-8 file. This is IMPORTANT.

4. Type Update-ApplicationAreaData. This command reads the ControlsWithAppArea.csv file and updates the source TXT files for lines where the value in the NewApplicationArea column is not equal to the value in the ApplicationArea column.

TIP: To improve performance, remove all lines that were not changed or copy all lines that were modified into a new Excel worksheet and then save as CSV.

5. Import, compile, and export the TXT files that were modified by the Update-ApplicationAreaData command so that they are ready for commit. Import/export is required to place the ApplicationArea property line in the right place among other properties.