AI coding assistants are powerful tools, but they work best when used thoughtfully. This guide provides best practices for integrating AI assistance into your AL development workflow.
You are still the developer. The AI is a tool to enhance your productivity, not a replacement for your expertise.
✅ Good Approach:
❌ Poor Approach:
Always review AI-generated code:
// AI might generate this:
procedure CalculateDiscount(Amount: Decimal): Decimal
begin
exit(Amount * 0.1); // Always 10% discount
end;
// But you need to verify it matches requirements:
// - Is 10% correct for all scenarios?
// - Should it vary by customer type?
// - Are there discount limits?
// - Should it read from setup?
Better context = better results:
✅ Provide:
❌ Avoid:
Temp1
, DoStuff
Generate scaffolding first, then refine:
Create a codeunit skeleton for "Sales Order Processor" with procedures for:
- ValidateOrder
- CalculateTotals
- ProcessPayment
- PostOrder
Implement the ValidateOrder procedure with these checks:
- Customer exists
- All lines have positive quantities
- Credit limit not exceeded
Check AI-generated code for:
Correctness
AL Best Practices
Business Central Standards
Performance
Don’t expect perfection on first try:
// Initial prompt
Create a procedure to import customers from CSV
// After reviewing generated code
Add validation for required fields: Name and Email
// After further review
Add error logging and return a list of failed imports
// Final refinement
Add telemetry tracking for import metrics
AI can catch common issues:
Review this code for:
- Potential bugs
- Performance issues
- AL best practice violations
- Missing error handling
AI review is a supplement, not a replacement:
The AI might miss context:
// AI might flag this as inefficient:
Customer.SetRange("No.", CustNo);
if Customer.FindFirst() then
Customer.Name := NewName;
// But might miss that in your context, you're in a loop
// processing thousands of customers, which is inefficient
Use AI for documentation drafts:
Generate XML documentation for this codeunit
Then review and enhance:
When AI generates code changes:
Update this procedure and its XML documentation to include the new parameter
AI can help with user docs too:
Create user documentation explaining how to set up customer discount categories.
Target audience: Business users, not developers.
Create a test codeunit structure for testing the Sales Order Processor
Include test methods for each public procedure
Create a helper procedure that sets up test data:
- One customer with normal credit limit
- One customer with exceeded credit
- Sample items with prices
- Sales header with lines
AI-generated tests might miss:
Create tests for this procedure before we refactor it
Refactor this procedure to extract the discount calculation into a separate function
Verify Tests Still Pass Run your test suite to confirm behavior unchanged
Review Changes Understand what changed and why
✅ Good for:
❌ Be Careful with:
Ask for Explanations:
Explain why this code uses Commit instead of direct posting
Request Alternatives:
Show me three different ways to implement this validation,
with pros and cons of each
Learn Patterns:
Show me the standard AL pattern for implementing a document posting routine
Don’t become dependent:
AI doesn’t automatically write optimal code:
// AI might generate this:
for i := 1 to Customer.Count do begin
Customer.Get(i);
ProcessCustomer(Customer);
end;
// You should refactor to:
if Customer.FindSet() then
repeat
ProcessCustomer(Customer);
until Customer.Next() = 0;
Always check AI-generated code for:
Be careful what’s in your workspace:
AI might not catch security issues:
// AI might generate this:
procedure ExecuteSQL(SQLStatement: Text)
begin
// Direct SQL execution - potential SQL injection!
end;
// You need to catch security concerns
Establish team guidelines:
For AI-generated code:
Help your team:
Critical Security Code
Highly Specialized Logic
Exploration and Learning
Quick, Simple Tasks
Monitor how AI affects your work:
Ensure quality isn’t suffering:
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.