Skip to content
Using OpenAI to write AL code for Business Central

Writing code with a text-based AI for Business Central

Daniel Gorski
Daniel Gorski December 03, 2022
2 min read

What/Who is OpenAI?

OpenAI was founded in 2015 by a group of leading researchers and tech industry figures, including Elon Musk and Sam Altman. The organization's mission is to develop and promote friendly AI that will benefit humanity as a whole. To achieve this goal, OpenAI conducts cutting-edge research in areas such as machine learning, natural language processing, and computer vision.

https://openai.com/

How does it work?

Login or register on openai.com and start a new thread:

ChatGPT's empty starting screen showing example prompts, capabilities, and limitations before any question has been asked

Ask anything you want:

ChatGPT response explaining what Microsoft Dynamics 365 Business Central is, after being asked

Nice :)!

So lets go for the next one:

ChatGPT confirming it understands AL code after being asked

Pretty cool! And what about some specific requirements?

ChatGPT outlining the fields for a

And now AL code:

ChatGPT generating the actual AL code for the Gift Card table in a syntax-highlighted code block, after being asked to write the table and page in AL

Wow, not bad or? Ok you need to adjust some properties but overall it's pretty cool:

table 50100 "Gift Card"
{
    DataClassification = CustomerContent;
    fields
    {
        field(1; "Gift Card ID"; Code[20])
        {
            DataClassification = CustomerContent;
        }
        field(2; "Card Number"; Code[20])
        {
            DataClassification = CustomerContent;
        }
        field(3; "Expiration Date"; Date)
        {
            DataClassification = CustomerContent;
        }
        field(4; "Card Value"; Decimal)
        {
            DataClassification = CustomerContent;
        }
        field(5; "Customer ID"; Code[20])
        {
            DataClassification = CustomerContent;
        }
    }
    keys
    {
        key(PK; "Gift Card ID")
        {
            Clustered = true;
        }
    }
}

page 50100 "Gift Card Details"
{
    layout
    {
        area(Content)
        {
            group("Card Information")
            {
                field("Card Number"; "Card Number")
                {
                }
                field("Expiration Date"; "Expiration Date")
                {
                }
                field("Card Value"; "Card Value")
                {
                }
                field("Customer"; "Customer ID")
                {
                }
            }
        }
    }
}

Related posts

▸ All posts
Set up a custom BC25 repository

BC25 Base App Repo: Find All References in AL

September 19, 2024 · Daniel Gorski

Build your own BC25 repository from the base app, platform packages and assemblies so Find All References works across Microsoft's code in VS Code.

Read More
Read More: Increase Your DEV productivity with your own BC25 REPO
Default Line Type behavior in Business Central

Document Default Line Type in Business Central

May 07, 2024 · Daniel Gorski

The 'Document Default Line Type' in Business Central only applies to the first line. A small AL event subscriber keeps it for every new line.

Read More
Read More: The Line Type Myth: Default Line Types in Business Central
AL runtime versions in Business Central

Business Central Runtime Versions List

February 06, 2024 · Daniel Gorski

Which AL runtime version belongs to which Business Central release, from runtime 1.0 (BC 12) to 16.0 (BC 27), and how to pick the runtime in app.json.

Read More
Read More: Navigating the Runtime Landscape in Business Central