Business Central Dataverse Entity Generator
Generates AL table objects from Microsoft Dataverse entities using ALTPGen and PowerShell automation. Automates the COMPLETE workflow: table ID allocation, command execution, error detection/fixing, file organization with BCS prefix, original file deletion, and automatic permission set updates.
⚡ FULLY AUTOMATED: Agent takes control of the terminal and executes all commands automatically. User interaction only required for authentication (browser popup for first-time OAuth).
🚨 TERMINAL TOOLS REQUIRED: This skill REQUIRES terminal command execution. If unavailable, agent must decline to proceed.
Prerequisites
- Terminal tools enabled (REQUIRED)
- AL Language extension installed in VS Code (includes ALTPGen)
- Azure AD App Registration with
Dynamics CRM > user_impersonationpermission - Access to target Dataverse environment
- PowerShell scripts configured in
.github/skills/bc-dataverse-entity-generator/scripts/
Automated Workflow
Step 0: Check Terminal Tools Availability
BEFORE starting, verify terminal tools are available:
if terminal tools NOT available:
❌ This process requires terminal command execution to be enabled.
The bc-dataverse-entity-generator skill cannot run manually because it requires:
- Automatic error detection and path fixing
- Real-time monitoring of ALTPGen output
- Automated file organization and cleanup
- Permission set updates
Please enable terminal tools in VS Code agent settings to use this skill.
STOP — do not proceed
Step 1: Analyze Request & Determine Next Table ID
- Extract entity name from user request (lowercase: "account", "contact", "quote")
- Scan existing tables in
src/Table/*.al - Extract table IDs using regex:
table\s+(\d+) - Find highest ID and add 1
- Verify within
app.jsonidRanges
Step 2: Execute PowerShell Generation Script
Build and execute command:
cd .github\skills\bc-dataverse-entity-generator\scripts
powershell -ExecutionPolicy Bypass -File ".\Generate-Entity.ps1" -Entity "{entity}" -BaseId {tableId}
Agent MUST execute directly via terminal tools
Inform user while executing:
Generating {Entity} CDS table...
Entity: {entity}
Table ID: {tableId} (next available)
Note: Browser may prompt for authentication (first run only)
Monitor terminal output for completion or errors.
Step 3: Error Handling & Auto-Fix
ALTPGen Path Error:
- Search for
altpgen.exein VS Code extensions:C:\Users\{User}\.vscode\extensions\ms-dynamics-smb.al-*\bin\win32\altpgen\altpgen.exe - Find latest version automatically
- Update
$AltpgenPathin Generate-Entity.ps1 - Re-execute generation script
Base Path Error:
- Add extra
Split-Pathto calculate correct project root - Update script
- Re-execute
Other Errors:
- Authentication: Inform user to complete browser popup
- Entity not found: Verify entity name (lowercase) exists in Dataverse
- Duplicate ID: Find next available ID, re-execute with new ID
- Network: Check ServiceUri and connectivity
Step 4: Post-Generation File Organization
Automatic steps:
-
Locate generated file in project root (e.g.,
Account.al,CDSaccount.Table.al) -
Read file content and apply BCS prefix:
- Find table declaration:
table \d+ "CDS {Entity}" - Update to:
table {id} "BCS CDS {Entity}"
- Find table declaration:
-
Create properly named file:
- Write content to:
src/Table/BCSCDS{Entity}.Table.al - Example:
Account.al→src/Table/BCSCDSAccount.Table.al
- Write content to:
-
Delete original file from project root to prevent duplicate object errors
-
Update permission set (
AGENTDEMO.permissionset.al):- Parse existing Permissions section
- Add
tabledata "BCS CDS {Entity}"=RIMD,in tabledata section (alphabetical order) - Add
table "BCS CDS {Entity}"=X,in table section (alphabetical order) - Maintain proper comma placement (last entry ends with
;)
-
Confirm completion:
✅ {Entity} CDS table generated successfully!
Created: src/Table/BCSCDS{Entity}.Table.al
Table ID: {tableId}
Table Name: "BCS CDS {Entity}"
✅ Cleaned up: Deleted {originalFile} from project root