My adventure with using ChatGPT continues. This time, I’m looking into its ability to read AL code. Check out the video:

In this video, Erik explores whether ChatGPT can read and understand AL code well enough to produce useful documentation. Having previously tested ChatGPT’s ability to write AL code, he shifts the focus to code comprehension — feeding AL functions into ChatGPT and asking it to generate documentation, summaries, and even refactored variable names. The results are surprisingly impressive, though not without some rough edges.
From Writing Code to Reading Code
A few weeks prior, Erik made a video where he tried to teach ChatGPT how to write AL code. That experiment went reasonably well — they got some workable code out of it — though generating AL still wasn’t as polished as generating Python or C++ code. But it raised an interesting question: if ChatGPT can write code, can it also read code, understand it, and produce documentation?
That’s exactly what this video puts to the test.
The Code Under Test
Erik uses code from a project he’s been working on called “Remote Records” — a feature for his toolbox that allows one Business Central environment to read data from another environment. He mentions that since the original video, performance has improved roughly 140 times, making it actually usable.
He also has a simple AL project set up to demonstrate. Here’s the table definition used in the demo project:
table 50100 "Customers"
{
DataClassification = ToBeClassified;
fields
{
field(1; "No."; Code[20])
{
DataClassification = ToBeClassified;
}
field(2; "Name"; Text[100])
{
DataClassification = ToBeClassified;
}
field(3; "Address"; Text[100])
{
DataClassification = ToBeClassified;
}
}
keys
{
key(PK; "No.")
{
Clustered = true;
}
}
}
Along with a card page and list page to surface the data:
page 50100 "Customers"
{
PageType = Card;
SourceTable = Customers;
layout
{
area(Content)
{
group("Customer Information")
{
field("No."; Rec."No.")
{
ApplicationArea = All;
}
field("Name"; Rec."Name")
{
ApplicationArea = All;
}
field("Address"; Rec."Address")
{
ApplicationArea = All;
}
}
}
}
}
page 50101 "Customers List"
{
PageType = List;
SourceTable = Customers;
CardPageId = 50100;
layout
{
area(Content)
{
repeater(Rec)
{
field("No."; Rec."No.")
{
ApplicationArea = All;
}
field("Name"; Rec."Name")
{
ApplicationArea = All;
}
field("Address"; Rec."Address")
{
ApplicationArea = All;
}
}
}
}
}
pageextension 50101 "Customers List Action" extends "Customer List"
{
actions
{
addlast(Processing)
{
action("View Card")
{
ApplicationArea = All;
Promoted = true;
PromotedCategory = Process;
trigger OnAction()
begin
Page.RunModal(Page::"Customers List");
end;
}
}
}
}
Test 1: Documenting a Blob-to-Base64 Function
The first function Erik feeds to ChatGPT is a procedure that takes a field reference to a Blob field and returns its content as a Base64-encoded string. He pastes the function in and politely asks: “Please write documentation for this AL function.”
Turbo Mode Response
The turbo version returned a straightforward paragraph-style description:
- Correctly identified that the function takes a Blob field reference
- Explained that it extracts Blob data using a temporary Blob, converts it to an InStream, then uses the Base64 Convert codeunit
- Noted that the parameter is passed by reference
- Correctly described the return type as a text value representing the Base64-encoded string
Plus (GPT-4) Response
The Plus version produced a more structured, formatted response with clear sections for input parameters, output, and functionality. It broke down each step of the function individually. However, when it attempted to generate an example usage, things went sideways — it labeled the code as SQL and produced an example that was mostly unusable, though the general intent was correct.
Erik’s verdict: “Even without the example, this is pretty nice.”
Test 2: Documenting a JSON-to-Record Function
Next, Erik tried a function called “JSON to Ref” — a procedure that takes a JSON object and maps its data into a record reference. This is a more complex function involving iteration over JSON keys, field number extraction, and dynamic field assignment.
ChatGPT’s Plus version produced documentation that:
- Correctly identified the function as mapping data from a JSON object to a Dynamics 365 Business Central database record
- Described both input parameters: the JSON object and the record reference
- Correctly noted that the function does not return a value — it modifies the record reference directly
- Walked through the for-each loop logic, field number extraction, and field existence checking
- Even understood Erik’s “sloppy variable names” like single-character identifiers
When Erik reminded ChatGPT that the var keyword indicates a parameter passed by reference (which can work as a return value), it adjusted its documentation to say the function “modifies the ref parameter to contain the data.”
One limitation: ChatGPT couldn’t fully figure out the naming convention where JSON keys are formatted as “F” followed by a field number (e.g., “F1”, “F2”), and the function uses Substring(2) to strip the prefix and evaluate the field number.
Test 3: Documenting “Assign Value to Field”
The third and most complex function was “Assign Value to Field” — a longer procedure that takes a JSON token and a field reference, then uses a case statement to determine the field type and assign the value accordingly.
ChatGPT produced solid documentation:
- Identified the two input parameters (field ref and JSON token)
- Explained the case statement logic for determining field type
- Listed supported field types including Text, Boolean, Date, Decimal, and others
When Erik asked for a concise summary, ChatGPT delivered a tight, accurate paragraph:
“The Assign Value to Field function is a local procedure that takes a JSON token and a field reference as input and assigns the value from the JSON token to the field represented by the field ref. The function uses a case statement to determine the type of the field and extracts the value from the JSON token using the appropriate method based on the field type. The extracted value is then assigned to the field using the FR.Value property. The function can handle various field types including Text, Boolean, Date, Decimal, and more.”
Erik’s reaction: “Bingo. I don’t know what to say — this is actually pretty good.”
Bonus: Refactoring Variable Names
As a bonus experiment, Erik asked ChatGPT to refactor one of his functions with better variable names, since he admittedly used “sloppy” single-character names. The results were mixed — ChatGPT attempted the refactoring but seemed to treat the code as VB.NET rather than AL, highlighting that ChatGPT still doesn’t fully recognize AL as its own distinct language.
Key Observations
- Turbo vs. Plus produces different output styles: Turbo gave paragraph-style descriptions while Plus (GPT-4) produced structured documentation with sections for inputs, outputs, and functionality.
- Code examples are unreliable: ChatGPT’s generated AL code examples were frequently wrong — misidentifying the language as SQL or CSS and producing unusable sample code. Asking it to omit examples and just describe usage works better.
- Documentation quality is genuinely useful: The descriptions of function behavior, parameters, and return values were consistently accurate and well-written.
- AL language awareness is still weak: ChatGPT doesn’t fully recognize AL as a language, sometimes confusing it with SQL, CSS, or VB.NET. This limits its ability to generate correct code but doesn’t significantly impact its ability to read and document code.
- You still need to verify: As Erik emphasizes, you cannot blindly copy what ChatGPT produces. You need to review and make sure it makes sense.
Conclusion
ChatGPT proves to be a surprisingly capable tool for generating AL code documentation. While it struggles with writing correct AL code examples and sometimes misidentifies the language, its ability to read, understand, and describe AL functions is impressive. It correctly identifies parameters, return values, control flow logic, and even understands concepts like pass-by-reference semantics. For developers looking to speed up the documentation process for their Business Central extensions, ChatGPT can serve as a powerful first-draft tool — just be sure to review and refine what it produces before committing it to your project.