GitHub copilot for X++

GitHub Copilot—a powerful AI pair programmer—can boost your productivity by suggesting code snippets, generating boilerplate, and even helping you reason about complex logic.

So this can helps you with

  • Speed up routine tasks : – Generating common patterns—queries, batch scaffolding, unit tests—becomes a one-liner in comments.
  • Discover best practices :- Copilot often suggests modern constructs (buffered selects, firstOnly, table joins via Query APIs).
  • Improve code consistency :- When guided by your comments and naming conventions, Copilot helps maintain a uniform style across modules.
  • On-demand explanations :- Through Copilot Chat, you can ask “Why did you choose QueryBuildRange here?” or “How do I handle transactions safely?”

Set up Copilot for X++ in Visual Studio

Prerequisites
  • Visual Studio 2022 or newer with Dynamics 365 extensions installed
  • GitHub Copilot subscription (included with GitHub Enterprise Cloud, GitHub Team, or standalone Copilot plan)
Installation Steps
  1. Install the GitHub Copilot Extension
    • Open Visual Studio.
    • Go to Extensions → Manage Extensions.
    • Search for “GitHub Copilot”, click Download, then restart Visual Studio or simply add it from the get tools and feature if using visual studio 2022
  2. Sign In to Copilot
    • After restart, open View → GitHub → Copilot (or Copilot Chat).
    • Click Sign in, and authenticate with your GitHub account that has Copilot access.
Crafting Effective Prompts

Copilot excels when given clear, concise “intent comments.” Treat comments as mini-specifications:

// GOAL: Return a List of all active customers in CustTable
public static List getActiveCustomers()
{
    List result = new List(Types::Record);
    CustTable cust;
    //copilot : get active customers from CustTable
}

you may get something like below

while select * from cust
    where cust.AccountType == CustVendAccountType::Cust
    && cust.Blocked == NoYes::No
    && cust.VatNum != ''
    && cust.Currency == 'USD'
{
    result.addEnd(cust);
}
Scaffolding a Batch Class
// GOAL: Create a batch class for processing large customer datasets
class CustomerDataBatch implements SysOperationBatchable
{
    // Copilot: implement description(), canCancel(), new(), run(), pack(), unpack()
}

may produce following skeleton

   // GOAL: Create a batch class for processing large customer datasets
   class CustomerDataBatch implements SysOperationBatchable
   {
       // Copilot: implement description(), canCancel(), new(), run(), pack(), unpack()
       public static str description()
       {
           return "Batch processing for customer data";
       }
       public static boolean canCancel()
       {
           return true;
       }
       public static SysOperationBatchable new()
       {
           return new CustomerDataBatch();
       }
       public void run()
       {
           // Implement the logic to process customer data
           // This could involve reading from a file, processing records, and updating the database
           // For example:
           CustomerTable customer;
           while select * from customer
           {
               // Process each customer record
               // For example, update a field or perform calculations
               customer.FieldToUpdate = someValue;
               customer.update();
           }
       }
       public void pack(SysOperationBatchablePack pack)
       {
           // Implement packing logic if needed
           // This could involve serializing data to be passed to the run method
       }   
       public void unpack(SysOperationBatchablePack pack)
       {
           // Implement unpacking logic if needed
           // This could involve deserializing data received from the pack method
       }
       public void cancel()
       {
           // Implement cancellation logic if needed
           // This could involve setting a flag to stop processing
       }
       public void progress()
       {
           // Implement progress reporting logic if needed
           // This could involve updating a progress bar or logging progress
       }
       public void finalize()
       {
           // Implement finalization logic if needed
           // This could involve cleaning up resources or logging completion
       }
       public void validate()
       {
           // Implement validation logic if needed
           // This could involve checking data integrity or ensuring required fields are populated
       }
       public void runBatch()
       {
           // Implement the logic to run the batch process
           // This could involve scheduling the batch job or executing it immediately
           SysOperationService service = new SysOperationService();
           service.run(this);
       }

similarly you can generate unit tests , performance optimise the code and involve in the deep reasoning with Copilot Chat

May need reviews and adjust the code manualy .

Leave a Reply