Ir al contenido

Introduction to AL and Environment

Deep fundamentals of Application Language (AL), underlying architecture, and advanced configuration of VS Code and the tenant.

0views

In our DevSecOps and Data Engineering culture, it is imperative to stop treating ERP systems (such as Dynamics 365 Business Central) as “black boxes” or simple web interfaces. To extract maximum performance and customize the system at the core level, we must descend to the source code level and understand its underlying architecture.

AL is a structured, declarative, and strongly typed programming language. It was designed exclusively by Microsoft to extend the business logic and data model of Business Central (replacing the former C/AL).

Working with AL is very similar to working with Infrastructure as Code (IaC) (such as Terraform or Ansible). We do not modify the database by clicking in an interface; we define in plain text files (.al) how we want the database (Tables), the logic (Codeunits), the interface (Pages), and the APIs (Queries) to be.

Subsequently, this code is compiled into a package or extension (.app) and deployed to the server. Microsoft does not allow altering its standard base code; all our programming acts as an “additional layer” (Extension) that attaches to the ERP.

2. Underlying Architecture (The NST and SQL Server)

Sección titulada «2. Arquitectura Subyacente (El NST y SQL Server)»

To program efficiently, we must understand how Business Central processes our instructions:

  • Data Layer: Under the hood, everything resides in a Microsoft SQL Server engine (in Azure SQL for Cloud environments).
  • Application Layer (NST): The Navision Server Tier is the “brain”. It translates our AL code into SQL queries and renders the HTML/JSON that users see or APIs consume. Understanding this is vital to avoid overloading the NST memory.

We develop locally, but we compile against a Sandbox environment in the cloud. This is our base configuration:

  1. Visual Studio Code (VS Code): Our Integrated Development Environment (IDE).
  2. “AL Language” Extension (Microsoft): Provides the compiler, autocompletion (IntelliSense), debugging tools, and the connection to the tenant.
  3. (Recommended optional) “AL Object Designer” Extension: A very useful visual explorer to navigate through Microsoft's base tables and discover how standard fields are named.

To create a new project, we open the VS Code Command Palette (Ctrl + Shift + P) and run AL: Go!. The wizard will ask us for:

  • A local path to save the project.
  • The deployment destination: We will always choose “Microsoft cloud sandbox” (NEVER Production for development phases).

This will generate the base structure, including the hidden folder .vscode with the file launch.json, and the root file app.json.

The .vscode/launch.json file is our umbilical cord to the Microsoft server. A loose configuration here is the main cause of connection and deployment errors.

We must configure it with extreme precision, avoiding generic values (such as default).

{
"version": "0.2.0",
"configurations": [
{
"name": "Conexión a Sandbox PORTELCORE",
"request": "launch",
"type": "al",
"environmentType": "Sandbox",
// 1. Nombre EXACTO del entorno (Sensible a mayúsculas y minúsculas)
// Esto se obtiene del Admin Center de Business Central.
"environmentName": "Sandbox-Dev",
// 2. Tenant ID: Usar el GUID alfanumérico garantiza que evitamos fallos de DNS o redirección.
"tenant": "a1b2c3d4-e5f6-7a8b-9c0d-1e2f3a4b5c6d",
// 3. Objeto de inicio: 22 es la lista de clientes. Cuando pulsemos F5, se abrirá esta pantalla.
"startupObjectId": 22,
"startupObjectType": "Page",
"breakOnError": "Default",
"launchBrowser": true,
// 4. Parámetros de Telemetría y Debugging avanzados
"enableLongRunningSqlStatements": true,
"enableSqlInformationDebugger": true
}
]
}

5. Metadata and Dependency Management (app.json)

Sección titulada «5. Gestión de Metadata y Dependencias (app.json)»

The app.json file is our extension's manifest. It defines who we are, which version we are publishing and, most critically, what we depend on.

In the AL ecosystem, we cannot compile unless we first download the “Symbols” (the ERP's precompiled libraries). The app.json tells VS Code exactly which version of the symbols it should look for on the server.

{
"id": "56a4f575-efca-45f3-8a35-43c3ab4c9adf",
"name": "Entradas_Salidas_AL",
"publisher": "Portelcore DevSecOps",
"version": "1.0.0.0",
"brief": "Gestión optimizada de datos y extensiones.",
// Dependencias de otras apps. Si no usamos módulos raros, dejar vacío o con lo básico.
"dependencies": [],
// EL PUNTO DE RUPTURA: La versión de "application" debe coincidir con la de nuestro Sandbox.
// Si pedimos la 27.0 y el server tiene la 25.0, todo el proyecto fallará.
"application": "25.0.0.0",
"platform": "25.0.0.0",
"runtime": "15.0", // Versión del motor de ejecución (NST).
"idRanges": [
{
"from": 50100,
"to": 50149 // Nuestro bloque de IDs reservados.
}
]
}

6. Environment Synchronization (The “Symbol Pull”)

Sección titulada «6. Sincronización del Entorno (El “Pull” de Símbolos)»

The final step before writing our first line of code is to synchronize our VS Code with the cloud.

  1. We verify that our hidden folder .alpackages is empty (or created).
  2. We run the command: Ctrl + Shift + P -> AL: Download Code (or AL: Download Symbols).
  3. The system will request authentication (Device Login) via a code in the browser. We will use our administrator credentials.
  4. If the launch.json and app.json files are correct, we will see in the console that packages such as Microsoft_Application.app are being downloaded.

Our local machine now knows the entire ERP database structure. We are ready to program.

  • ✓ Connectivity: Successful download of symbols in the VS Code console (exit code 0).
  • ✓ Version: Directive coherence of runtime and application in app.json with the active NST version.
  • ✓ Authentication: Login flow completed via Device Login through OAuth 2.0.