### NAV Specific Example: OIOUBL Path Setup Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/NAVPatterns/patterns/easy-update-of-setup-or-supplementary-information/index.md Illustrates the implementation of IsOIOUBLPathAvailable and VerifyAndSetOIOUBLPath in the Sales & Receivables Setup table (311) for the DK version. ```al Local Procedure IsOIOUBLPathAvailable(...) Procedure VerifyAndSetOIOUBLPath(...) ``` -------------------------------- ### Example: Few-Shot Prompting for Getter Methods Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/agentic-coding/GettingStarted/glossary.md Demonstrates how to use few-shot prompting by providing an example of a getter method to guide the AI in creating a new one for a different field. ```AL Create getter methods like this example: procedure GetCustomerName(): Text[100] begin exit("Customer Name"); end Now create a getter for "Customer Email" ``` -------------------------------- ### Good Code: Consistent Line Start Keywords Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/NAVPatterns/3-cal-coding-guidelines/readability/line-start-keywords/index.md This example demonstrates the recommended practice of starting control flow keywords on a new line for improved code readability and maintainability. ```al IF IsContactName THEN ValidateContactName ELSE IF IsSalespersonCode THEN ValidateSalespersonCode ELSE IF IsSalesCycleCode THEN ValidatSalesCycleCode; ``` -------------------------------- ### Call Setup Verification and Update Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/NAVPatterns/patterns/easy-update-of-setup-or-supplementary-information/index.md Example of calling the VerifyAndSetX procedure from a processing codeunit to ensure necessary setup is in place before proceeding. ```al .. SetupTable.VerifyAndSetX .. ``` -------------------------------- ### Good Code Example: Line Start Keywords Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/BestPractices/line-start-keywords/index.md Illustrates the correct way to use control flow keywords, placing each on its own line for better structure and readability. ```al if IsContactName then ValidateContactName() else if IsSalespersonCode then ValidateSalespersonCode() else if IsSalesCycleCode then ValidatSalesCycleCode(); ``` -------------------------------- ### Project Generation Example for Customer Surveys Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/agentic-coding/CommunityResources/Agents/cursor-agent.md Shows an example of using Cursor to scaffold an entire Business Central extension for customer surveys. This includes generating setup tables, survey and response tables, associated pages, email sending logic, and API endpoints. ```al "Create a BC extension for customer surveys with: - Setup tables - Survey and response tables - Pages for all tables - Email sending logic - API for mobile access" Cursor scaffolds entire extension. ``` -------------------------------- ### Prompt with Example for Event Subscriber Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/agentic-coding/GettingStarted/effective-prompting.md Shows how to provide a code pattern example to guide the AI in creating specific event subscribers. This helps ensure the generated code matches the desired structure and logic. ```plaintext Create an event subscriber for OnAfterValidate on Sales Header's "Sell-to Customer No." field, similar to this pattern: [EventSubscriber(ObjectType::Table, Database::"Sales Header", 'OnAfterValidateEvent', 'Sell-to Customer No.', false, false)] local procedure OnAfterValidateSellToCustomerNo(var Rec: Record "Sales Header") begin // Your implementation here end; The subscriber should copy the Newsletter Email from the Customer to the Sales Header. ``` -------------------------------- ### Initialize Source Code Setup Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/NAVPatterns/patterns/singleton/singleton-table/setup-table/index.md This method demonstrates initializing all fields of a singleton setup table with default values during company initialization. This reduces implementation effort. ```AL method InitSourceCodeSetup() var SourceCodeSetup: Record "Source Code Setup"; begin SourceCodeSetup.InitFields(); SourceCodeSetup.Insert(true); end; ``` -------------------------------- ### Send Welcome Email Example Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/agentic-coding/GettingMore/documentation.md Example of how to call the SendWelcomeEmail procedure from the Customer Email Manager codeunit. Checks for success and displays a message. ```al CustomerEmailManager: Codeunit "Customer Email Manager"; begin if CustomerEmailManager.SendWelcomeEmail('C001') then Message('Welcome email sent successfully'); end; ``` -------------------------------- ### Hugo Folder Structure Example Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/Contributing/InstallHugo/ManuallyOnWindows11/index.md This text block illustrates the recommended folder structure for Hugo installations on Windows. ```text C:\Hugo ├── Bin # Binaries └┬─ Sites # Hugo Site Repositories └── alguidelines # Hugo Source for alguidelines.dev ``` -------------------------------- ### Bad Code Example: Line Start Keywords Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/BestPractices/line-start-keywords/index.md Demonstrates incorrect usage where control flow keywords are not at the start of a line, reducing readability. ```al if IsContactName then ValidateContactName() else if IsSalespersonCode then ValidateSalespersonCode() else if IsSalesCycleCode then ValidatSalesCycleCode(); ``` -------------------------------- ### AL Documentation Generation Prompt Examples Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/agentic-coding/GettingStarted/effective-prompting.md Examples of prompts for generating documentation for AL code or features. Specify the type of documentation needed, such as XML comments or user guides. ```plaintext Generate XML documentation comments for all procedures in this file ``` ```plaintext Create a README explaining what this extension does and how to install it ``` ```plaintext Write user documentation for this new feature ``` -------------------------------- ### Split Subscriber Logic into Separate Codeunits Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/BestPractices/SubscriberCodeunits/index.md Separate subscriber logic into distinct codeunits to improve organization and maintainability. This example shows splitting setup subscribers into 'LTE Setup Subs' and 'RHE Setup Subs'. ```AL codeunit 2037325 "LTE Setup Subs" { SingleInstance = true; [EventSubscriber(ObjectType::Codeunit, Codeunit::"Manual Setup", 'OnRegisterManualSetup', '', false, false)] local procedure OnRegisterManualSetup(sender: Codeunit "Manual Setup") var RegisterLTEManualSetup: codeunit "Register LTE Manual Setup"; begin RegisterLTEManualSetup.RegisterLTEManualSetup(); end; } codeunit 2037324 "RHE Setup Subs" { SingleInstance = true; [EventSubscriber(ObjectType::Codeunit, Codeunit::"Manual Setup", 'OnRegisterManualSetup', '', false, false)] local procedure OnRegisterManualSetup(sender: Codeunit "Manual Setup") var RegisterRHEManualSetup: codeunit "Register RHE Manual Setup"; begin RegisterRHEManualSetup.RegisterRHEManualSetup(); end; } ``` -------------------------------- ### Initialize Git Submodules and Install npm Packages Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/Contributing/InstallHugo/UsingPowershellOnWindows11/index.md After Hugo installation, run these commands in the repository root to update Git submodules and install project dependencies via npm. ```powershell git submodule update --init --recursive --depth 1 ``` ```powershell npm install ``` -------------------------------- ### Verify and Set Setup Information Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/NAVPatterns/patterns/easy-update-of-setup-or-supplementary-information/index.md Defines procedures to check if required setup information is available and to open the relevant page for updates if it's missing. Call this pattern from your processing codeunits. ```al Local Procedure IsXAvailable : Boolean If field X <> '' then Exit(True) Exit(false) VerifyAndSetX If IsXAvailable then Exit; If Confirm('Field X is missing a value. Do you want to update it now?') then Open the card page in edit mode If not IsXAvailable then Error(Field X is missing a value. Please correct it.) ``` -------------------------------- ### Vague vs. Specific Prompt Example Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/agentic-coding/GettingStarted/effective-prompting.md Illustrates the difference between vague and specific prompts for AI code generation. Use specific prompts to get more precise results. ```plaintext Create a page ``` ```plaintext Create a card page for the Customer table that displays these fields: - No. - Name - Address - Phone No. Include FactBoxes for Sales Statistics and Contact Information. ``` -------------------------------- ### Good Example: Using Argument Table for Readability Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/NAVPatterns/patterns/argument-table/index.md This example shows how to use a temporary table as an argument table. It significantly improves code readability by reducing the function signature to a single argument. ```AL TAB 50003 VAT Return Data PROCEDURE FillInVATReturnData@1200001(VAR VATReturnData@1200000 : Record 50003); VATReturnData.INIT; VATReturnData.NumberOfCopies := GetDefaultNumberOfCopies; VATReturnData.Uploaded := FALSE; FillInVATReturnData(VATReturnData); ``` -------------------------------- ### Composer Mode Example for Loyalty Points System Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/agentic-coding/CommunityResources/Agents/cursor-agent.md Shows an example of using Composer mode (Cmd+I) to generate multiple related AL files for a new feature, such as a loyalty points system. Cursor creates tables, pages, and codeunits, ensuring they are properly connected and follow AL patterns. ```al Press Cmd+I (Composer) Type: "Add a loyalty points system with table, page, and codeunit" Cursor creates: - Table 50100 "Loyalty Points Entry" - Page 50100 "Loyalty Points List" - Page 50101 "Loyalty Points Card" - Codeunit 50100 "Loyalty Points Manager" All properly connected and following AL patterns ``` -------------------------------- ### Install Hugo and Node.js using PowerShell Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/Contributing/InstallHugo/UsingPowershellOnWindows11/index.md Execute this script to set the execution policy, update security protocols, install Chocolatey, and then install Node.js and Hugo Extended. ```powershell Set-ExecutionPolicy Bypass -Scope Process -Force [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072 Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) choco install -y nodejs choco install -y hugo-extended ``` -------------------------------- ### Good Example: Argument Table with Encapsulated Options Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/NAVPatterns/patterns/argument-table/index.md This example demonstrates how to group arguments within a record, allowing for additional arguments without changing the function signature. Options are encapsulated within the table, improving maintainability. ```AL PROCEDURE GetTableSyncSetupW1@3(VAR TableSynchSetup@1000 : Record 2000000135); BEGIN SetTableSyncSetup(DATABASE::"Sales Header",0,TableSynchSetup.Mode::Check); SetTableSyncSetup(DATABASE::"Posting Exch. Column Def",104025,TableSynchSetup.Mode::Copy); SetTableSyncSetup(DATABASE::"Payment Export Data",0,TableSynchSetup.Mode::Force); END; ``` -------------------------------- ### Install NAB AL Tools MCP globally Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/agentic-coding/CommunityResources/Tools/nab-al-tools-mcp.md Install the tool globally for command-line access. Requires npm. ```bash npm install -g @nabsolutions/nab-al-tools-mcp ``` -------------------------------- ### Install Customer Engagement Suite Extension Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/agentic-coding/GettingMore/documentation.md Installs the Customer Engagement Suite extension using the NAVApp command. Ensure you have the correct version and path. ```powershell Publish-NAVApp -ServerInstance BC210 -Path "CustomerEngagementSuite.app" Install-NAVApp -ServerInstance BC210 -Name "Customer Engagement Suite" ``` -------------------------------- ### Install NAB AL Tools MCP via npx Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/agentic-coding/CommunityResources/Tools/nab-al-tools-mcp.md Use this command to run the NAB AL Tools MCP server without a global installation. ```bash npx -y @nabsolutions/nab-al-tools-mcp ``` -------------------------------- ### Example Prompt: Table Extension Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/agentic-coding/GettingStarted/effective-prompting.md A comprehensive prompt for creating a table extension, including fields, triggers, and documentation requirements. ```plaintext Create a table extension for Table 36 "Sales Header" that adds these fields: - "Requested Delivery Date" (Date) - "Special Instructions" (Text[250]) - "Requires Approval" (Boolean) Add triggers: - Set "Requires Approval" to true when amount exceeds $10,000 - Validate "Requested Delivery Date" is not in the past Include XML documentation for all fields. ``` -------------------------------- ### Bad Code Example Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/Contributing/Templates/BestPractice/index.md Illustrates code that does not adhere to best practices. Use this as a reference for what to avoid. ```al PutCodeblocksHere() ``` -------------------------------- ### Good Practice: BEGIN on Same Line Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/NAVPatterns/3-cal-coding-guidelines/readability/begin-as-an-afterword/index.md Place the BEGIN keyword on the same line as THEN, ELSE, or DO, preceded by a single space. This enhances code readability. ```AL IF ICPartnerRefType = ICPartnerRefType::"Common Item No." THEN BEGIN ... END; ``` -------------------------------- ### Valid Version Check for First Installation Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/agentic-coding/vibe-coding-rules/al-upgrade.md The only acceptable use of version checks is to determine if an application is being installed for the first time. This example checks if the DataVersion is '0.0.0.0'. ```al trigger OnInstallAppPerCompany() var AppInfo: ModuleInfo; begin NavApp.GetCurrentModuleInfo(AppInfo); if (AppInfo.DataVersion() <> Version.Create('0.0.0.0')) then exit; // Insert installation code here end; // Alternative approach trigger OnInstallAppPerCompany() var AppInfo: ModuleInfo; begin if AppInfo.DataVersion().Major() = 0 then SetAllUpgradeTags(); CompanyInitialize(); end; ``` -------------------------------- ### Initialize Record on Page Open Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/NAVPatterns/patterns/singleton/singleton-table/setup-table/index.md This code ensures a record exists when the setup page is opened for the first time. It initializes and inserts a new record if none is found. ```AL OnOpenPage() RESET; IF NOT GET THEN BEGIN INIT; INSERT; END; ``` -------------------------------- ### Queue Processing Example Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/patterns/command-queue/index.md Demonstrates how to use the Command Queue pattern to post multiple sales orders and display a completion message. Filters sales orders and adds commands to the queue before executing them. ```AL codeunit 50105 PatchPostQueue { procedure PatchPost() begin FilterSalesOrdersToPost(); if not SalesOrders.Findset(false) then exit(); // Nothing to post repeat AddSalesOrderToQueue(SalesOrder."No."); until SalesOrders.Next() = 0; AddMessageToQueue('Posting Complete'); ExecuteQueue(); end; local procedure ExecuteQueue() var object : interface "ICommand"; begin repeat object := queue.Pop(); object.Execute(); until queue.GetSize() = 0; end; local procedure FilterSalesOrdersToPost() begin // Filter Sales Orders here end; local procedure AddMessageToQueue(message : Text) var t: Codeunit MessageCommander; object: Interface ICommand; begin t.SetText(message); object := t; queue.Push(object); end; local procedure AddSalesOrderToQueue(No : Text) var SaleOrderCommander: Codeunit SalesOrderPostCommander; object: Interface ICommand; begin SaleOrderCommander.SetSalesOrderNumber(No); object := SaleOrderCommander; queue.Push(object); end; var SalesOrders : Record "Sales Header"; queue: Codeunit Queue; } ``` -------------------------------- ### Create Test Data Setup Procedure Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/agentic-coding/GettingStarted/best-practices.md Prompt AI to generate a helper procedure for setting up realistic test data, including various customer scenarios, items, and sales documents, to facilitate comprehensive testing. ```al 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 ``` -------------------------------- ### Generate XML Documentation Draft Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/agentic-coding/GettingStarted/best-practices.md Use AI to generate a first draft of XML documentation for a codeunit. This provides a starting point that can then be personalized with business context and examples. ```al Generate XML documentation for this codeunit ``` -------------------------------- ### AL-Go Workspace Structure Example Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/agentic-coding/vibe-coding-rules/al-testing.md Illustrates the recommended directory structure for an AL-Go project, separating application code from test code. ```plaintext Repository/ ├── .AL-Go/ ├── .github/ ├── App/ │ ├── src/ │ │ ├── Setup/ │ │ ├── Feature1/ │ │ ├── Feature2/ │ │ ├── APIs/ │ ├── app.json │ └── launch.json ├── Test/ │ ├── src/ │ │ ├── SetupTests/ │ │ ├── Feature1Tests/ │ │ ├── Feature2Tests/ │ │ ├── IntegrationTests/ │ ├── app.json │ └── launch.json └── al.code-workspace ``` -------------------------------- ### Bad Practice: Large Subscriber Codeunit Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/BestPractices/SubscriberCodeunits/index.md This example demonstrates a large subscriber codeunit that registers multiple unrelated setup entries. It violates the principle of keeping codeunits small and focused. ```AL codeunit 2037325 "Setup Subs" { SingleInstance = true; [EventSubscriber(ObjectType::Codeunit, Codeunit::"Manual Setup", 'OnRegisterManualSetup', '', false, false)] local procedure OnRegisterManualSetup(sender: Codeunit "Manual Setup") var AppId: ModuleInfo; NameListLbl: Label 'Linked Texts Framework - List', Locked = true; DescriptionListLbl: Label 'Edit linked texts', Locked = true; KeyWordListLbl: Label 'LT,Distri,Technical,Functional,Reports', Locked = true; NameReportLbl: Label 'Linked Texts Framework - Reports', Locked = true; DescriptionReportLbl: Label 'View linked texts reports', Locked = true; KeyWordReportLbl: Label 'LT,Distri,Technical,Functional,Reports', Locked = true; begin navapp.GetCurrentModuleInfo(AppId); Sender.Insert(NameListLbl, DescriptionListLbl, KeyWordListLbl, page::"LTE Linked Text List", AppId.Id(), "Manual Setup Category"::General); Sender.Insert(NameReportLbl, DescriptionReportLbl, KeyWordReportLbl, page::"LTE Linked Texts Reports", AppId.Id(), "Manual Setup Category"::General); end; [EventSubscriber(ObjectType::Codeunit, codeunit::"Manual Setup", 'OnRegisterManualSetup', '', false, false)] local procedure OnRegisterManualSetup(sender: Codeunit "Manual Setup") var AppId: ModuleInfo; NameLayoutLbl: Label 'Report Helper - Layout', Locked = true; DescriptionLayoutLbl: Label 'Set up or update report layout list', Locked = true; KeyWordLayoutLbl: Label 'RH,Distri,Technical,Functional,Reports,Layout', Locked = true; NameCaptionsLbl: Label 'Report Helper - Captions', Locked = true; DescriptionCaptionsLbl: Label 'Set up or update captions list', Locked = true; KeyWordCaptionsLbl: Label 'RH,Distri,Technical,Functional,Reports,Captions', Locked = true; NameFunctionsLbl: Label 'Report Helper - Functions', Locked = true; DescriptionFunctionsLbl: Label 'Set up or disable functions', Locked = true; KeyWordFunctionsLbl: Label 'RH,Distri,Technical,Functional,Reports,Functions', Locked = true; NameDFCLbl: Label 'Report Helper - Default Footer', Locked = true; DescriptionDFCLbl: Label 'Set up or update default footer', Locked = true; KeyWordDFCLbl: Label 'RH,Distri,Technical,Functional,Reports,Default,Footer', Locked = true; begin navapp.GetCurrentModuleInfo(AppId); Sender.Insert(NameLayoutLbl, DescriptionLayoutLbl, KeyWordLayoutLbl, page::"RHE Report Layout List", AppId.Id(), "Manual Setup Category"::General); Sender.Insert(NameCaptionsLbl, DescriptionCaptionsLbl, KeyWordCaptionsLbl, page::"RHE Captions", AppId.Id(), "Manual Setup Category"::General); Sender.Insert(NameFunctionsLbl, DescriptionFunctionsLbl, KeyWordFunctionsLbl, page::"RHE Functions", AppId.Id(), "Manual Setup Category"::General); Sender.Insert(NameDFCLbl, DescriptionDFCLbl, KeyWordDFCLbl, page::"RHE Default Footer Card", AppId.Id(), "Manual Setup Category"::General); end; } ``` -------------------------------- ### Consistent Event IDs for Telemetry Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/agentic-coding/GettingMore/telemetry.md Use consistent and meaningful event IDs for telemetry logging to ensure clarity and ease of analysis. Examples include processing started, completed, errors, and warnings. ```al SALESORD-001: Processing started SALESORD-002: Processing completed SALESORD-E001: Processing error SALESORD-W001: Validation warning SALESORD-P001: Performance warning ``` -------------------------------- ### Migrate Items and Item Unit of Measure without Staging Tables Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/NAVPatterns/patterns/data-migration-facade/index.md This example demonstrates migrating item data and their associated units of measure using the Data Migration Facade. It includes initializing the migration, creating items if they don't exist, setting various item properties, migrating dependencies like units of measure, and updating the migration status. Use this when direct migration without staging tables is preferred. ```al trigger OnRun(); var ItemDataMigrationFacade: Codeunit "Item Data Migration Facade"; ItemNumber: Integer; ItemJson: Text; begin // loop on items retrieved through a web service for example for ItemNumber := 1 to ExternalWebService.GetItemCount do begin ExternalWebService.GetItem(ItemNumber,ItemJson); // create item using the facade if not ItemDataMigrationFacade.CreateItemIfNeeded(ItemJson.ItemNumber,ItemJson.ItemName1, ItemJson.ItemName2,ConvertItemType(ItemJson.ItemType)) then exit; // item already exists // set some fields using the facade ItemDataMigrationFacade.SetVendorItemNo(ItemJson.VendItemNumber); ItemDataMigrationFacade.SetUnitVolume(ItemJson.Volume); ItemDataMigrationFacade.SetAlternativeItemNo(ItemJson.AltItemNumber); if ItemJson.PrimaryVendor <> '' then ItemDataMigrationFacade.SetVendorNo(ItemJson.PrimaryVendor); // migrate dependencies MigrateItemUnitOfMeasure(ItemDataMigrationFacade,ItemJson); // modify the item (+run trigger) to save the changes made by setters ItemDataMigrationFacade.ModifyItem(true); // update the status in the migration dashboard DataMigrationStatusFacade.IncrementMigratedRecordCount('My Migration Type',Database::Item,1); end; end; ``` ```al procedure MigrateItemUnitOfMeasure(ItemDataMigrationFacade : Codeunit "Item Data Migration Facade"; ItemJson : Text) var MyUnitCodeStagingTable: Record "My Unit Code Staging Table"; DataMigrationStatusFacade: Codeunit "Data Migration Status Facade"; DescriptionToSet: Text[10]; UnitCodeJson: Text; begin if ItemJson.UnitCode = '' then // log an error using the Data migration façade DataMigrationStatusFacade.RegisterErrorNoStagingTablesCase( 'My Migration Type',Database::Item,'Unit of measure is empty.'); if ExternalWebService.GetUnitCode(ItemJson.UnitCode,UnitCodeJson) then DescriptionToSet := UnitCodeJson.Description; ItemDataMigrationFacade.CreateUnitOfMeasureIfNeeded(ItemJson.UnitCode, DescriptionToSet); // set the unit of measure on the item ItemDataMigrationFacade.SetBaseUnitOfMeasure(ItemJson.UnitCode); end; ``` -------------------------------- ### Get Unique Notification ID - C/AL Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/NAVPatterns/patterns/notifications/in-context-notifications/index.md Provides a unique GUID for a notification. This ID can be hard-coded or generated at runtime using the CREATEGUID function. Skipping this call results in a new notification ID being generated. ```al EXIT('2712AD06-C48B-4C20-820E-347A60C9AD00'); ``` -------------------------------- ### Bad Code: Inconsistent Line Start Keywords Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/NAVPatterns/3-cal-coding-guidelines/readability/line-start-keywords/index.md This example shows a less readable code structure where control flow keywords are not consistently placed at the beginning of a new line, making it harder to follow the logic. ```al IF IsContactName THEN ValidateContactName ELSE IF IsSalespersonCode THEN ValidateSalespersonCode ELSE IF IsSalesCycleCode THEN ValidatSalesCycleCode; ``` -------------------------------- ### Learn Standard Patterns with AI Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/agentic-coding/GettingStarted/best-practices.md Use this prompt to ask AI to demonstrate standard patterns for implementing common routines in AL. ```text Show me the standard AL pattern for implementing a document posting routine ``` -------------------------------- ### Insert Record, Apply Template, and Insert Related Templates Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/NAVPatterns/patterns/create-data-from-templates/index.md This snippet demonstrates the complete process of creating a customer record, applying a configuration template to it, and then inserting related templates such as dimensions. ```al // First insert a record Customer.INSERT(TRUE); // Apply a template RecRef.GETTABLE(Customer); ConfigTemplateMgt.UpdateRecord(ConfigTemplateHeader,RecRef); RecRef.SETTABLE(Customer); // Insert Dimensions -- related templates MiniDimensionsTemplate.InsertDimensionsFromTemplates(ConfigTemplateHeader,Customer."No.",DATABASE::Customer); ``` -------------------------------- ### Good Example Code Snippet Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/agentic-coding/vibe-coding-rules/README.md An example of code that adheres to a specific AL coding rule. ```al // Good example [code example] ``` -------------------------------- ### Access Singleton Record for Rules Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/NAVPatterns/patterns/singleton/singleton-table/_index.md This code demonstrates how to access the singleton record (General Ledger Setup) to retrieve configuration rules, such as rounding precision for unit amounts. ```AL GLSetup.GET; UnitCostCurrency := ROUND(...,GLSetup."Unit-Amount Rounding Precision"); ``` -------------------------------- ### Bad Example Code Snippet Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/agentic-coding/vibe-coding-rules/README.md An example of code that violates a specific AL coding rule, intended to show what to avoid. ```al // Bad example (avoid) [code example] ``` -------------------------------- ### Example AL Project Structure Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/agentic-coding/GettingStarted/setup.md Organize your AL project files into a clear directory structure. This helps AI assistants understand your project's layout and provide more relevant suggestions. ```plaintext MyExtension/ ├── .vscode/ │ ├── settings.json │ └── launch.json ├── src/ │ ├── Tables/ │ ├── Pages/ │ ├── Codeunits/ │ ├── Reports/ │ └── ... ├── test/ │ └── ... ├── app.json └── README.md ``` -------------------------------- ### Example YouTube Embed Code Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/NAVPatterns/patterns/instructions-in-the-ui/index.md This is an example of the HTML code snippet typically obtained from video hosting services to embed a video. ```html ``` -------------------------------- ### Install GitHub Copilot Extension Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/agentic-coding/CommunityResources/tools.md Use this extension ID to install GitHub Copilot in VS Code. Requires a GitHub Copilot subscription. ```plaintext Extension ID: GitHub.copilot ``` -------------------------------- ### Prompt with and without Context Example Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/agentic-coding/GettingStarted/effective-prompting.md Demonstrates how providing context significantly improves AI understanding for code modifications. Always include relevant details about your project. ```plaintext Add a field to store email ``` ```plaintext I'm extending the Customer table. Add a new field called "Newsletter Email" to store the email address customers want to use for newsletters. This is separate from their primary email. Make it a Text field with length 80. ``` -------------------------------- ### Bad Practice: BEGIN on New Line Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/NAVPatterns/3-cal-coding-guidelines/readability/begin-as-an-afterword/index.md Avoid placing the BEGIN keyword on a new line when it follows THEN, ELSE, or DO. This reduces readability. ```AL IF ICPartnerRefType = ICPartnerRefType::"Common Item No." THEN BEGIN ... END; ``` -------------------------------- ### Composer Mode Prompt Example Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/agentic-coding/CommunityResources/Agents/cursor-agent.md Provide clear and detailed instructions when using Composer mode to generate AL code. Specify tables, pages, codeunits, and desired functionality. ```plaintext Create AL customer loyalty system with: - Tier setup table (code, name, min points, discount %) - Customer points table (customer no, points, tier code) - List and card pages for both - Codeunit to calculate and assign tiers - Event subscriber to update on purchase Follow AL naming conventions and add XML docs ``` -------------------------------- ### Install AL Variable Helper Extension Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/agentic-coding/CommunityResources/tools.md Use this extension ID to install the AL Variable Helper extension in VS Code for auto-declaring and managing variables. ```plaintext Extension ID: rasmus.al-var-helper ``` -------------------------------- ### Install AL Language Extension Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/agentic-coding/CommunityResources/tools.md Use this extension ID to install the core AL language support extension in VS Code. This is essential for AL development. ```plaintext Extension ID: ms-dynamics-smb.al ``` -------------------------------- ### Install GitHub Copilot Chat Extension Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/agentic-coding/CommunityResources/tools.md Use this extension ID to install GitHub Copilot Chat in VS Code. Requires a GitHub Copilot subscription. ```plaintext Extension ID: GitHub.copilot-chat ``` -------------------------------- ### Run Hugo Server Source: https://github.com/microsoft/alguidelines/blob/main/README.md Use this command to start the Hugo development server locally. Visit http://localhost:1313/ in your browser to preview the website changes as you make them. Press Ctrl+C to stop the server. ```bash $ hugo server Web Server is available at http://localhost:1313/ (bind address 127.0.0.1) Press Ctrl+C to stop ``` -------------------------------- ### AL Tab Completion Example Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/agentic-coding/CommunityResources/Agents/cursor-agent.md Demonstrates real-time AI suggestions for AL code, similar to Copilot, providing complete procedure stubs based on comments. ```al // Type a comment /// Validate customer credit limit // Cursor suggests complete procedure procedure ValidateCreditLimit(CustomerNo: Code[20]): Boolean var Customer: Record Customer; begin // Full implementation suggested end; ``` -------------------------------- ### Good Code Example for Action Image Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/NAVPatterns/3-cal-coding-guidelines/ux/actions-images/index.md This code shows the correct way to define an action with an assigned image, adhering to best practices. ```al { 7 ;1 ;Action ; CaptionML=ENU=Customer - &Balance; RunObject=Report 121 Image=Report } ``` -------------------------------- ### Call OIOUBL Path Setup Verification Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/NAVPatterns/patterns/easy-update-of-setup-or-supplementary-information/index.md Shows how to call the VerifyAndSetOIOUBLPathSetup procedure from the Sales-Post + Print codeunit (82) when processing a sales invoice. ```al IF ("EAN No." <> '') THEN SalesSetup.VerifyAndSetOIOUBLPathSetup(SalesHeader."Document Type"); ``` -------------------------------- ### Install AL Test Runner Extension Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/agentic-coding/CommunityResources/tools.md Use this extension ID to install the AL Test Runner extension in VS Code for running and debugging AL tests. ```plaintext Extension ID: jamespearson.al-test-runner ``` -------------------------------- ### Install AL Object Designer Extension Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/agentic-coding/CommunityResources/tools.md Use this extension ID to install the AL Object Designer extension in VS Code for browsing and managing AL objects. ```plaintext Extension ID: martonsagi.al-object-designer ``` -------------------------------- ### Correct 'begin' Placement in AL Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/BestPractices/begin-as-an-afterword/index.md Place the 'begin' keyword on the same line as 'then', preceded by a space, for improved code clarity. ```AL if ICPartnerRefType = ICPartnerRefType::"Common Item No." then begin ... end; ``` -------------------------------- ### Install AL Code Outline Extension Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/agentic-coding/CommunityResources/tools.md Use this extension ID to install the AL Code Outline extension in VS Code for code navigation and structure visualization. ```plaintext Extension ID: davidfeldhoff.al-code-outline ``` -------------------------------- ### AI Performance Optimization Example (AL) Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/agentic-coding/GettingStarted/best-practices.md Illustrates a common performance anti-pattern in AL code generation by AI and the recommended refactoring for efficiency. ```al // 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; ``` -------------------------------- ### AL Code Explanation Prompt Examples Source: https://github.com/microsoft/alguidelines/blob/main/content/docs/agentic-coding/GettingStarted/effective-prompting.md Examples of prompts for explaining AL code at different levels of detail. Useful for understanding existing code or learning AL development. ```plaintext // Simple explanation Explain what this function does ``` ```plaintext // Detailed explanation Explain this procedure in detail, including the purpose of each parameter and the business logic flow ``` ```plaintext // For learning Explain this code as if I'm new to AL development ```