top of page

AI with GitHub Copilot will Revolutionize AL Development for Microsoft Dynamics 365 Business Central


 

Addressing Application Language Development Challenges


1 Complexity of AL Extensions involves specialized knowledge and extensive coding to execute complex business logic and integrations.


2 Repetitive Tasks Creating boilerplate code and managing common functionalities can be tedious and susceptible to errors.


3 Maintaining Consistency It can be challenging to maintain consistent coding practices and naming conventions within a team.

 

How Copilot for GitHub Empowers Application Language (AL) Extension Development


Automation

Copilot for GitHub can automatically generate code for common AL functionality, saving developers time and effort.


Natural Language Processing

Copilot for GitHub understands natural language, allowing developers to express their ideas and have Copilot translate them into working code.


Consistency and Quality

Copilot for GitHub enforces coding best practices and maintains consistency, improving code quality and maintainability.

 

Automation


Scaffolding

Copilot can generate boilerplate code for common Application Language components, such as pages, tables, and codeunits.


GitHub Copilot is an AI-powered code completion tool that assists developers by suggesting lines of code and entire functions. It works with various programming languages and can generate code for different components based on comments or partial code inputs. Since you are interested in examples for ALE components like pages, tables,  and codeunits, here’s how you might use Copilot to help generate these examples in a development environment like AL for Microsoft Dynamics 365 Business Central.


1.AL Table

When creating a table in AL for Business Central, you typically define fields and properties. Here’s how you might start the comment for Copilot to generate a table for customer data:

// AL Table to store customer information with fields for ID, Name, Address, and Phone


Based on this comment, Copilot can suggest the following AL code:


 

2. AL Page

Creating a page involves defining the layout and the fields that will be displayed. You can start with a comment like:

// AL Page to display customer records with fields ID, Name, Address, and Phone

Copilot may suggest something like this:


 

3. AL Codeunit

Codeunits are used for writing business logic. Here’s how you might instruct Copilot to generate a simple codeunit to handle customer validation:


// AL Codeunit for customer validation logic, checking if customer name and phone are provided

Copilot’s suggested code might look like:

codeunit 50100 "Customer Validation" { procedure ValidateCustomer(CustomerRec: Record Customer) result: Boolean { if CustomerRec.Name = '' then error('Customer name must be provided.');

    if CustomerRec.Phone = '' then

        error('Customer phone number must be provided.');

    return true;

}


By using such comments, GitHub Copilot can assist you in generating the boilerplate code for these common components in AL, helping speed up the development process. Remember, the quality and applicability of Copilot’s suggestions can vary, so always review the generated code for correctness and best practices.

 

Integrations


Copilot can create integration logic to connect Application Language Extensions with other Business Central modules and external systems.


GitHub Copilot can aid in generating code for integration tasks between AL extensions and other modules within Microsoft Dynamics 365 Business Central, as well as external systems. The key to leveraging Copilot effectively is providing clear, concise descriptions of what the integration should accomplish. Below are several examples illustrating how you might prompt Copilot to generate integration logic.


1.Integrating with the Inventory Module


For integrating a custom extension with the Inventory module, you might want to synchronize inventory items or quantities. Here’s how you could phrase your comment for Copilot:

// AL Code to synchronize inventory items from the custom product extension to the Inventory module Based on this, Copilot might suggest a code snippet like:


 

2.Connecting to an External REST API

If you're developing logic to connect Business Central to an external REST API (e.g., for updating customer data), here’s how you might start:

// AL Code to update customer data in an external CRM system via REST API

Copilot could generate a function like:


 

3.Event Publishing for Module Interaction

To facilitate interactions between modules, you might use events in Business Central. Here’s a comment prompt for Copilot:

// AL Code to publish an event after a sales order is finalized, to notify other modules

Copilot might help with:


 

These examples illustrate the potential of GitHub Copilot in accelerating the development of complex integration logic within Business Central's AL language, fostering more efficient and error-reducing coding practices.

 

Customizations


Copilot can assist in building custom functionality, tailored to the specific needs of the business.


I asked Copilot to write a codeunit template for automated lot assignment for sales order lines in Business Central using AL - based upon a project description document that I would upload. "After upload of my project document file, could you generate examples of tables, pages and codeunits needed to create this customization for BC?"


Here is the project document I uploaded:

Auto-Assign Lot Numbers to Sales Order Lines

 Begin

Scenario:

·       Sales Orders are being inserted into Business Central by True Commerce EDI. The SO Lines do NOT have Lot #’s assigned.

·       The SO Lines need Lot Assignments in order to be picked for shipment.

·       Lot Assignments are now being done manually. Client wants it automated.

Automation Requirements:

Assigning Lot #’s

·       Lot #’s will be assigned for each Sales Order line based on the Lot Expiration Date.

·       No Lot #’s may be assigned with an Expiration Date earlier than 9 months from the Order (Document) Date of the Sales Order.

·       The assignment process chooses the Lots with the earliest Expiration Date, but not earlier than 9 months from the Sales Order Date.

·       If there are multiple lots with the same Expiration Date, then the system will choose the one with the lowest Lot Code. The quantity may consume multiple lots, so the choice would be:

o   Only lots with Expiration Dates 9 or more months into the future (based on the Order Date of the Sales Order).

o   Earliest Expiration Date first

o   Lowest Lot Code if same Expiration Date

o   Assign multiple lots if needed until quantity required is assigned.

·       When a Sales Order has been fully assigned Lots for each line (if they exist according to the rules above), then the custom field “Lots Assigned” will be automatically set to “Yes”.

·       The existing BC “Picking List by Order” Report can be modified to show all Lot Assignments and Shorts. This report can be run for one Sales Order, a range, All, or (if we add a filter) only those orders with Lot Assignments complete.

·       A system job will run every few hours to auto-assign Lot #’s as described above. The timing will need to be coordinated with the EDI insertions so as not to interfere.

·       Each Sales Order Card will have a promoted menu option to manually run the process for that order if the EDI process inserts new Sales Orders between the system job runs or this automation conflicts with the TrueCommerce inserts, or the job was placed on Hold for some error.

·       Any error handling which redoes the Lot Assignment, either singly or globally will need to clear the existing assignments and redo them.

·       Any Lot Assignment process must first start with removing any existing assignments in case of partial assignments.

·       The Recurring system job to assign Lots will only run against Sales Order Cards that have not already been processed (e.g. the Lots Assigned field = “No”. If you want to reset all open Sales Orders to “No”, then Edit in Excel and reset the Lots Assigned Option to “false”. Then publish back to BC.

·       If the Lot Assignment Job in the Job Queue is in an Error State it will be displayed on relevant users’ BC Desktops, depending on their Role. This way the error can be handled by the user and the job can be rerun manually in the foreground at the Job Queue.

·       The end-user will be able to restrict the Lot Assignment Extension by Company. There will be a custom  field (true/false button) added to the Company Information Window, which will default to “false”. Only when set to “true” will the Lot Assignment Extension execute the new code.

 

Generating Reports:

·       Incomplete Lot Assignments Report:

o   After each system job Lot Assignment process is completed for all unassigned Sales Orders, the modified Picking List by Sales Order Report will be generated for all Sales Orders in that recently run Batch. The modified Picking List by Sales Order Report will show the complete information on each line of each Sales Order. This report will be emailed to the users who require it. It can be generated at any time by any authorized user.

o   The Client Admin will be provided a Page and underlying Table to manage this notification list, adding or deleting users as necessary.

Additional Request:

·       There is an existing “On Hand Lot Report”. This needs to be emailed on a schedule to specific users.

·       The Client Admin needs to manage this notification list, adding or deleting users as necessary.

End


Copilot responded:

"Thank you for uploading the detailed project description. Based on the requirements described in the document, we need to create several components in AL for Microsoft Dynamics 365 Business Central to automate the lot assignment process for sales orders. Here’s how we might design the necessary tables, pages, and codeunits for this customization:"

1. Table: Lot Information

We need a table to store information about each lot, including its expiration date and available quantity


2. Page: Lot Information

A page to view and manage the lots in the system



 

3. Codeunit: Automatic Lot Assignment

This codeunit will handle the logic of assigning lots to sales order lines based on the rules specified


 

4. Additional Features and Error Handling

• Error handling needs to be robust, managing partial assignments and ensuring transactions are correctly rolled back if necessary.

• Integration with EDI needs to ensure that the lot assignment process is triggered correctly after new orders are inserted.


This is a basic starting point. The actual implementation will need further refinement based on additional requirements, such as user permissions, detailed error logging, and optimizing the performance for large datasets. Make sure to test the code thoroughly in a sandbox environment to handle any edge cases or potential bugs.

 

Natural Language Processing


Rapid Prototyping:

Developers can describe their ideas in natural language, and Copilot will convert them into working code prototypes.

 

Knowledge Capture

Copilot can learn from the development team's coding patterns and preferences, improving its assistance over time.

 

Contextual Assistance

Copilot understands the context of the Application Language development, providing relevant suggestions and code examples.

 

Examples of Copilot using Natural Language Processing to make AL Development better and faster

GitHub Copilot's effectiveness in aiding the development of Application Language (AL) extensions for Microsoft Dynamics 365 Business Central relies heavily on its use of natural language processing (NLP). This capability allows Copilot to interpret descriptive comments or partial code snippets, providing developers with code suggestions that accelerate prototyping, enhance knowledge capture, and deliver contextual assistance. Here is how GitHub Copilot might leverage NLP in these scenarios, providing hypothetical code examples for each case.

1. Rapid Prototyping

Scenario: You're starting a new feature to manage customer loyalty points in Business Central. You begin by writing a high-level description of the main function.

Comment in Code:

// Function to calculate and update loyalty points based on the total invoice amount and customer category

GitHub Copilot's Suggested Code:




This example demonstrates rapid prototyping by allowing developers to quickly flesh out the core logic of new features without needing to draft every detail from scratch.

 

2. Knowledge Capture


Scenario: A developer is unfamiliar with handling transactions in Business Central and begins to draft a comment asking for help.

Comment in Code:

// How to handle database transactions when updating multiple records in Business Central

GitHub Copilot's Suggested Code:


 

This snippet instructs on correctly grouping modifications to ensure atomic transaction behavior, capturing domain-specific best practices for handling Business Central transactions.

 

3. Contextual Assistance

Scenario: You are working on integrating a custom module with the inventory system and you start with a comment.

// Integrate custom module with Business Central inventory to adjust stock based on sales

GitHub Copilot's Suggested Code:


This suggestion provides contextual assistance, showing how to adjust inventory levels based on sales, a common requirement when integrating new modules with existing systems.


Each of these examples highlights GitHub Copilot's potential in using Natural Language Processing to understand developers' intents from natural language comments and provide meaningful, contextually appropriate code suggestions that can accelerate development, reduce the learning curve, and enhance code quality in AL development for Business Central.

 

Code Quality and Consistency


Linting and Formatting

Copilot automatically enforces coding standards and best practices, ensuring a consistent codebase.

Example: Enforcing Coding Standards with GitHub Copilot and Additional Tools

Here's how you might integrate GitHub Copilot with other tools to promote coding standards and best practices in a BC Application Language development project:

1.Using GitHub Copilot for Code Suggestions:


Scenario: You are developing a custom module in AL to handle inventory adjustments.

Copilot Suggestion: You start typing a comment or a function signature, and Copilot might suggest



Here, Copilot suggests a basic inventory adjustment function. The use of Commit might be appropriate depending on the broader transaction context.

 

2. Linting and Formatting Tools for AL


Linting and formatting tools help identify problems in code before deployment, which can reduce time and costs. Linting tools, also known as lint tools, analyze source code for stylistic and programmatic errors. Formatting tools automatically format source code to make it easier to read and understand. Linting is different from formatting because linting analyzes how code runs, while formatting only restructures how it appears.


Tools like AL Linter or AL Formatter:

• After writing code, running it through linters and formatters can help ensure it adheres to coding standards specific to AL.

• These tools can enforce naming conventions, check for unused variables, and ensure best practices in error handling and transaction management.

 

3. Static Code Analysis Tools:

• Tools like the AL Code Analyzer:

• Integrate these tools into your CI/CD pipeline.


In software engineering, CI/CD or CICD is the combined practices of continuous integration and continuous delivery or, less often, continuous deployment. They are sometimes referred to collectively as continuous development or continuous software development. Wikipedia



They can analyze the codebase for potential errors, code smells, and even performance issues by enforcing rules such as avoiding overly complex  functions or ensuring proper transaction handling.

 

4.  Code Review Practices:

• Manual and Automated Reviews:

• Utilize GitHub pull requests for peer code reviews.

• Automated tools can be integrated to review pull requests and enforce rules, such as requiring certain test coverage or checking for specific code patterns.

 

5.  Pre-commit Hooks

• Using a version control system like Git with pre-commit hooks:

• Configure hooks to run formatting and linting before code is committed, ensuring all code meets the team’s standards.

• Example pre-commit hook for AL might include running AL Linter or AL Formatter before each commit.

 

Example Scenario Using Copilot in AL


Suppose you are developing a custom sales order processing feature in AL. You might write a comment or start defining a procedure, prompting Copilot to suggest:



With this suggestion:

Best Practices Enforced: Basic validation is implemented, checking the order status and document date.

Additional Steps: Enhance the function by adding more complex business rules validations, checking for credit limits, or ensuring inventory availability. After coding, use AL Code Analyzer to check for any potential issues or improvements.


While GitHub Copilot can accelerate development by suggesting code snippets and patterns, a consistent and standard-compliant codebase in AL often requires combining Copilot's capabilities with robust development practices, including code reviews, static analysis, and adherence to a structured coding standard.

 

Refactoring Suggestions

Copilot provides intelligent recommendations to improve the structure and maintainability of the Application Language Extension code.


Code improvements and Refactorings

GitHub Copilot, powered by AI, can assist developers by suggesting code improvements and refactorings, particularly by providing snippets that optimize or enhance existing code. While Copilot doesn't refactor code automatically in the traditional sense, it does provide intelligent suggestions based on the code context you're working within and the patterns it has learned from a vast corpus of publicly available code. Below are some examples of how GitHub Copilot could potentially help with refactoring and improving the maintainability of Application Language (AL) code used in extensions for Microsoft Dynamics 365 Business Central.


Example 1: Simplifying Conditional Logic

 

Example 2: Extracting Reusable Code


This approach promotes reuse and minimizes code duplication across similar procedures


Example 3: Improving Error Handling




Copilot Suggestion for Refactoring: To improve maintainability and error handling, Copilot might suggest adding detailed error messages and possibly a logging mechanism:



Example 4: Optimizing Loop Performance




 

This change uses ModifyAll to update all records at once where possible, reducing the number of writes to the database.


These examples illustrate how GitHub Copilot can suggest improvements based on typical coding patterns and practices. It's important to review all suggestions for suitability within your specific context, especially considering Business Central's transactional nature and the business logic implications of any change.

 

Inline Documentation


Copilot can generate comprehensive documentation and comments, enhancing the readability and understanding of the Application Language Extensions for Microsoft Dynamics 365 Business Central.


I asked Copilot, "Based on the Project.docx file I just uploaded, give me an example of Copilot generating comprehensive documentation and comments, enhancing the readability and understanding of the Application Language Extensions for Microsoft Dynamics 365 Business Central".


Response: "Example: Comprehensive Documentation for Automatic Lot Assignment"


This example of code documentation and comments provided by GitHub Copilot:

• Describes the purpose and usage of each function within the codeunit.

• Explains the parameters and processes involved, such as the criteria for lot selection and the business rules applied.

• Offers insights into the dependencies and effects of running this codeunit, helping both current and future developers understand the code's functionality and its impact on the system.

This comprehensive documentation approach can significantly enhance the maintainability and readability of the code, making it easier for teams to manage and extend their AL solutions effectively.

 

Reducing Development Time and Effort, without sacrificing quality. In fact - at better quality!







Faster Delivery

Increased Creativity

Improved Productivity

Copilot's automation and assistance capabilities enable developers to create Application Language Extensions for Microsoft Dynamics 365 Business Central more efficiently and quickly.

By handling repetitive tasks, Copilot frees AL Developers to focus on more innovative solutions.

Copilot's insights and recommendations help Application Language Developers write higher-quality code in less time.

 


Submitted by Steve Simon (and his trusty Copilot), PDG Consultants, Inc. (4/24/24)


5 Comments


mariahjohn862
6 days ago

I really appreciate the post you shared here. Great job! Please continue the good work.

Are you looking for what is the best website for MBA assignment help in USA? If yes, you should visit casestudyhelp.com, which is the right choice. They provide online MBA assignment help USA from professional MBA assignment expert writers in USA. Contact us today.

Like

Andrew Tate
Andrew Tate
Oct 29

I’m a fan of vaping, but I didn’t know about some of the safety tips mentioned here. I might try an Elf Bar Ottawa.

Like

Hazel Jones
Hazel Jones
Oct 26

Discover the step-by-step guide to logging into Facebook without any hassle. Quick, easy, and secure methods for accessing your Facebook account. Click to learn more.Get solutions for common Facebook login problems. Read our comprehensive guide to troubleshoot and fix your login issues quickly. Click to solve your problems now. Facebook Entrar Facebook Entrar

Like

Clark benson
Clark benson
Oct 21

Provide students with diverse and challenging content that requires critical analysis and synthesis of information from multiple sources. This includes texts, articles, videos, scientific data, historical documents, and more Incorporate collaborative pay to write my assignment experiences that encourage students to engage in discussions, debates, and peer feedback. Collaborative learning promotes active engagement, diverse perspectives, and the exchange of ideas.

Like

John Wilson
John Wilson
Sep 17

Struggling with your MBA assignments? MyAssignmentHelp.com offers top-notch MBA Assignment Writing Services online to help you excel. Our team of expert writers is well-versed in various MBA subjects, providing customized solutions tailored to your needs. We ensure high-quality content, in-depth research, and timely delivery to boost your academic performance. Whether it's case studies, essays, or research papers, our services are designed to meet your requirements. With MyAssignmentHelp.com, you can achieve academic excellence without the stress. Get in touch today for reliable and professional MBA assignment help.

Like
Recent Posts
1/2
Archive
Search By Tags
Follow Us
  • Facebook Basic Square
  • Twitter Basic Square
  • Google+ Basic Square