Skip to content
TXT2AL conversion guide

How-To Solve your issues after TXT2AL

Daniel Gorski
Daniel Gorski February 24, 2021
2 min read

or should I really run through all my files and convert the variables?

What's the case?

You convert your old C/AL Code and make them AL ready, right?

This is how you should do it:

  1. Export your C/AL-Objects as txt-File
  2. Split your Objects separately (I will provide a powershell script soon)
  3. Run this e.g. in cmd:
cd "C:\Program Files (x86)\Microsoft Dynamics 365 Business Central\140\RoleTailored Client"
txt2al.exe --source="C:\Install\Source" --target="C:\Install\Target"

Command prompt running txt2al.exe to convert GenJnlPostLine.Codeunit.al and SalesPost.Codeunit.al with zero errors

Get your converted files and import them into your repo in VC Code:

The converted GenJnlPostLine.Codeunit.al open in VS Code with dozens of

And as you can see, your variables are not recognized.

You could use a Regular Expression:

"(\d*)"

and replace it with:

$1

VS Code's regex find-and-replace panel with the pattern (\d*) and replacement $1 used to strip quotes from numeric record IDs Variable declarations such as GLSetup: Record 98 after the regex replace removed the quotes around each numeric ID

Or you could even use this PowerShell script or how I call it: "txt2AL Beautifier".

This PowerShell script works with a dictionary, which you can easily extend:

The txt2AL Beautifier PowerShell script's $mapping dictionary mapping numeric query IDs to their proper query names

And it will iterate through all given *.al files to convert these variables correctly:

$mapping = @{
  'Record "3"'     = 'Record "Payment Terms"'
  'Record "4"'     = 'Record "Currency"'
  'Record "5"'     = 'Record "Finance Charge Terms"'
  'Record "6"'     = 'Record "Customer Price Group"'
  'Record "7"'     = 'Record "Standard Text"'
  'Record "8"'     = 'Record "Language"'
  'Query "7300"'   = 'Query "Lot Numbers by Bin"'
  'Query "7301"'   = 'Query "Whse. Employees at Locations"'
  'Query "7345"'   = 'Query "Avail Qty. (Base) In QC Bins"'
  'Query "9060"'   = 'Query "Count Sales Orders"'
  'Query "9063"'   = 'Query "Count Purchase Orders"'
  'Query "9150"'   = 'Query "My Customers"'
  'Query "9151"'   = 'Query "My Vendors"'
  'Query "9152"'   = 'Query "My Items"'
}

$regexescape = $mapping.Keys | ForEach-Object { [Regex]::Escape($_) }
$regex = [Regex]($regexescape -join '|')

Get-ChildItem $PSScriptRoot -Filter *.al | ForEach-Object {
  $values = { $mapping[$args[0].Value] }
  $incomingfile = Get-Content $_.FullName -Raw
  $incomingfile = $regex.Replace($incomingfile, $values)
  Set-Content -Path ($_.DirectoryName + "\" + $_.BaseName + "_out.al") -Value $incomingfile
}

Get the full file here:
UsefulScripts/Powershell at main · byndit/UsefulScrpts (github.com)

Have Fun :)

Related posts

▸ All posts
Split multiline comments in Business Central

Split Multiline Text into Records

June 28, 2022 · Daniel Gorski

Learn how to split long multiline text into comment records in Business Central using AL and Regex — including a working editor example and useful patterns.

Read More
Read More: Split Multiline Text into Records
Split legacy NAV/Business Central object files with PowerShell

How-To Split C/AL Objects Using PowerShell

March 03, 2021 · Daniel Gorski

Need to split legacy NAV or Business Central C/AL object files from .txt exports? This PowerShell script automates the process – fast and reliable.

Read More
Read More: How-To Split C/AL Objects Using PowerShell
Fixing DNS issues in Docker Containers

Docker DNS Not Working in Windows Containers

June 13, 2025 · Malte Petersen

Docker container can't resolve host names? Set a DNS server inside the Windows container, or once for all containers in daemon.json. Two fixes.

Read More
Read More: Fixing DNS Issues in Windows-Based Docker Containers for Business Central Testing