### Assisted Setup Action Example Source: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-designing-navigate-pages Defines an action for an assisted setup guide, including its enabled state, position, image, and an OnAction trigger. ```AL Enabled = FinishEnable; InFooterBar = true; Image = Approve; trigger OnAction() begin Finished(); end; ``` -------------------------------- ### Good Code Example: Including Company-Initialize Source: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/analyzers/codecop-aa0235 This code shows the recommended implementation, including both 'OnInstallAppPerCompany' and the 'OnCompanyInitialize' event subscriber. This ensures that new companies receive the necessary setup when the extension is installed. ```AL codeunit 1160 "AP Install" { Subtype = Install; trigger OnInstallAppPerCompany() begin ... end; [EventSubscriber(ObjectType::Codeunit, Codeunit::"Company-Initialize", 'OnCompanyInitialize', '', false, false)] local procedure CompanyInitialize() begin ... end; } ``` -------------------------------- ### Registering an Assisted Setup Guide Source: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-designing-navigate-pages Subscribes to the 'OnRegisterAssistedSetup' event to register a new assisted setup guide for 'Add a to-do'. ```AL [EventSubscriber(ObjectType::Codeunit, Codeunit::"Guided Experience", 'OnRegisterAssistedSetup', '', true, true)] local procedure OnRegisterAssistedSetup() var AssistedSetup: Codeunit "Guided Experience"; GuidedExperienceType: Enum "Guided Experience Type"; AssistedSetupGroup: Enum "Assisted Setup Group"; VideoCategory: Enum "Video Category"; begin if not AssistedSetup.Exists(GuidedExperienceType::"Assisted Setup", ObjectType::Page, Page::"ToDoAssistedSetup") then AssistedSetup.InsertAssistedSetup( 'Add a to-do', 'Create a task for your team', 'Register a task for your team and assign people', 1, ObjectType::Page, Page::ToDoAssistedSetup, AssistedSetupGroup::Tasks, '', VideoCategory::Uncategorized, ''); end; ``` -------------------------------- ### Bad Code Example: Missing Company-Initialize Source: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/analyzers/codecop-aa0235 This code demonstrates the incorrect implementation where 'OnInstallAppPerCompany' is used without a corresponding 'OnCompanyInitialize' event subscriber. This can lead to missing setup in companies created after the extension installation. ```AL codeunit 1160 "AP Install" { Subtype = Install; trigger OnInstallAppPerCompany() begin ... end; } ``` -------------------------------- ### Example GET Request for setupCloudMigrations Source: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/administration/cloudmigrationapi/api/dynamics_setupcloudmigration_get An example of a GET request to the setupCloudMigrations endpoint, including the base URL and placeholders for environment and object IDs. ```http GET https://{businesscentralPrefix}/api/v1.0/companies({id})/setupCloudMigrations({id}) ``` -------------------------------- ### Registering a Custom Assisted Setup Guide Source: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-designing-navigate-pages This codeunit subscribes to the OnRegisterAssistedSetup event to add a custom assisted setup guide ('ToDoAssistedSetup') and creates a new category ('Tasks') on the Assisted Setup page. ```AL codeunit 50100 "AddToDoAssistedSetup" { [EventSubscriber(ObjectType::Codeunit, Codeunit::"Guided Experience", 'OnRegisterAssistedSetup', '', true, true)] local procedure OnRegisterAssistedSetup() var AssistedSetup: Codeunit "Guided Experience"; GuidedExperienceType: Enum "Guided Experience Type"; AssistedSetupGroup: Enum "Assisted Setup Group"; VideoCategory: Enum "Video Category"; begin if not AssistedSetup.Exists(GuidedExperienceType::"Assisted Setup", ObjectType::Page, Page::"ToDoAssistedSetup") then AssistedSetup.InsertAssistedSetup( // Link text for the assisted setup guide 'Add a to-do', // Short description, not shown on page 'Create a task for your team', // Text that shows in Description column 'Register a task for your team and assign people', 1, ObjectType::Page, Page::ToDoAssistedSetup, // Assign guide to Task category AssistedSetupGroup::Tasks, //Video URL not required '', VideoCategory::Uncategorized, //Help URL not required ''); end; } ``` -------------------------------- ### Example Response for Create Setup Cloud Migration Source: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/administration/cloudmigrationapi/api/dynamics_setupcloudmigration_create This is an example of a successful response (201 Created) when creating a setup cloud migration. It includes the created setupCloudMigration object. ```http HTTP/1.1 201 Created Content-type: application/json { "id" : "", "productId" : "", "sqlServerType" : "", "sqlConnectionString" : "", "runtimeName" : "", "runtimeKey" : "" } ``` -------------------------------- ### Get Extension Response Example Source: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/administration/api/dynamics_extension_get Example JSON response for a successful GET request to retrieve extension details. This object contains properties like packageId, id, displayName, version, and installation status. ```json { "packageId": "3252be43-93d6-4d6a-b603-cdc0f0f32a9e", "id": "3d5b2137-efeb-4014-8489-41d37f8fd4c3", "displayName": "Late Payment Prediction", "publisher": "Microsoft", "versionMajor": 18, "versionMinor": 0, "scope": 0, "isInstalled": true } ``` -------------------------------- ### InitializeFromSetup Method Source: https://learn.microsoft.com/en-us/dynamics365/business-central/application/base-application/report/microsoft.inventory.requisition.calculate-plan---req.-wksh. Initializes the report based on general setup configurations. This is the recommended method for initialization. ```AL procedure InitializeFromSetup() ``` -------------------------------- ### Run Setup from Command Prompt Source: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/deployment/install-using-setup Use Setup.exe with command-line options to automate or customize the installation process. Ensure you are in the correct directory or provide the full path to Setup.exe. ```bash C:\Program Files (x86)\Common Files\Microsoft Dynamics 365 Business Central\\Setup ``` -------------------------------- ### Response Body for Installed Apps Source: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/administration/administration-center-api_app_management Example JSON response body for the 'Get Installed Apps' endpoint, listing installed apps with details such as ID, name, version, state, and uninstallation information. ```json { "value": [ { "appId": guid, // Id of the installed app "name": string, // Name of the installed app "publisher": string, // Publisher of the installed app "version": string, // Version of the installed app "state": string, // (enum | "Installed", "UpdatePending", "Updating") "lastOperationId": guid, // Id of the last update operation that was performed for this app "lastUpdateAttemptResult": string // (enum | "Failed", "Succeeded", "Canceled", "Skipped") "lastUninstallOperationId": guid // Id of the last uninstall operation that was performed for this app "lastUninstallAttemptResult": string // (enum | "Failed", "Succeeded", "Canceled", "Skipped") "appType": string // (enum | "global", "tenant", "dev") "canBeUninstalled": boolean // Specifies whether the app can be uninstalled } ] } ``` -------------------------------- ### Get Currently Installed Extension PackageId by AppId Source: https://learn.microsoft.com/en-us/dynamics365/business-central/application/system-application/codeunit/system.apps.extension-management Retrieves the PackageId of the currently installed extension version using its AppId. Returns an empty GUID if not found. ```AL procedure GetCurrentlyInstalledVersionPackageIdByAppId(AppId: Guid): Guid ``` -------------------------------- ### Get Media Object GUID Example Source: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/media/media-mediaid-method This example demonstrates how to retrieve the GUID of a media object associated with a specific item record using the MediaId method. Ensure the 'My Items' table exists with a 'Media' data type field named 'Image'. ```AL var myItemRec: Record "My Items"; imageID: GUID; Text000: Label 'Item %1 has a media object with the following ID: %2'; begin myItemRec.Get('1'); mediaGuid := myItemRec.Image.MediaId; Message(Text000, myItemRec."No.", imageID); end; ``` -------------------------------- ### Example: Open, Write, and Close a File Source: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/file/file-close-method This example checks if a file exists, opens it in write mode, writes 'Hello World' to it, and then closes the file. If the file does not exist, an error message is displayed. This method is supported only in Business Central on-premises. ```AL var FileName: Text; TestFile: File; begin FileName := 'C:\TestFolder\TestFile2.txt'; if Exists(FileName) then begin TestFile.WriteMode(true); TestFile.Open(FileName); TestFile.Write('Hello World'); TestFile.Close; end else Message('%1 does not exist.', FileName); end; ``` -------------------------------- ### Get MediaSet GUID for an Item Record Source: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/mediaset/mediaset-mediaid-method This example demonstrates how to retrieve the MediaSet GUID for an item record using the MediaId method. It assumes the 'Picture' field is configured as a MediaSet. ```AL var item: Record Item; mediasetId: GUID; Text000: Label 'The GUID of the MediaSet is: %1'; begin item.Get('1000'); mediasetId := item.Picture.MediaId; Message(Text000, mediasetId); end; ``` -------------------------------- ### Example Background Task Codeunit Source: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-page-background-tasks A sample codeunit that gets the current system time, waits for a specified duration, and then gets the system time again. It returns the start time, wait duration, and end time as results. ```AL codeunit 50100 PBTWaitCodeunit { trigger OnRun() var Result: Dictionary of [Text, Text]; StartTime: Time; WaitParam: Text; WaitTime: Integer; EndTime: Time; begin if not Evaluate(WaitTime, Page.GetBackgroundParameters().Get('Wait')) then Error('Could not parse parameter WaitParam'); StartTime := System.Time(); Sleep(WaitTime); EndTime := System.Time(); Result.Add('started', Format(StartTime)); Result.Add('waited', Format(WaitTime)); Result.Add('finished', Format(EndTime)); Page.SetBackgroundTaskResult(Result); end; } ``` -------------------------------- ### Run Payment Registration Setup Source: https://learn.microsoft.com/en-us/dynamics365/business-central/application/base-application/codeunit/microsoft.bank.payment.payment-registration-mgt. Initiates the payment registration setup wizard. Use this to guide users through configuration if setup is not yet complete. ```AL procedure RunSetup() ``` -------------------------------- ### Get Latest Extension PackageId by AppId Source: https://learn.microsoft.com/en-us/dynamics365/business-central/application/system-application/codeunit/system.apps.extension-management Retrieves the PackageId of the latest installed version of an extension using its AppId. Returns an empty GUID if not found. ```AL procedure GetLatestVersionPackageIdByAppId(AppId: Guid): Guid ``` -------------------------------- ### Complete Setup Bound Action Source: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/administration/cloudmigrationapi/resources/dynamics_setupcloudmigration This example shows how to call the `completeSetup` bound action on the setupCloudMigration resource to complete setups for a batch. The response code is 204 and has no content. ```HTTP COMPLETESETUP https://://api/v1.0/companies({id})/setupCloudMigrations({id})/Microsoft.NAV.completeSetup ``` -------------------------------- ### Setup.exe Command-Line Options Source: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/deployment/install-using-setup These options allow for advanced control over the Business Central setup process, including silent installations and repair operations. ```bash /config ``` ```bash /help ``` ```bash /log ``` ```bash /quiet ``` ```bash /repair ``` ```bash /uninstall ``` -------------------------------- ### Example GET Account Request Source: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/api-reference/v2.0/api/dynamics_account_get An example of a GET request to retrieve an account from Business Central. ```http GET https://{businesscentralPrefix}/api/v2.0/companies({id})/accounts({id}) ``` -------------------------------- ### InitializeFromSetup Source: https://learn.microsoft.com/en-us/dynamics365/business-central/application/base-application/report/microsoft.inventory.requisition.calculate-plan---req.-wksh. Initializes the report from the general setup. ```APIDOC ## InitializeFromSetup ### Description Initializes the report from the general setup. ### Method AL Procedure ### Signature ``` procedure InitializeFromSetup() ``` ``` -------------------------------- ### Get documentAttachment Request Example Source: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/api-reference/v2.0/api/dynamics_documentattachment_get An example of a GET request to retrieve a document attachment from the Business Central API. ```HTTP GET https://{businesscentralPrefix}/api/v2.0/companies({id})/documentAttachments({id}) ``` -------------------------------- ### RunSetup Source: https://learn.microsoft.com/en-us/dynamics365/business-central/application/base-application/codeunit/microsoft.bank.payment.payment-registration-mgt. Runs the payment registration setup wizard to configure payment registration defaults. This procedure checks if setup is complete and guides users through configuration if needed. ```APIDOC ## RunSetup ### Description Runs the payment registration setup wizard to configure payment registration defaults. This procedure checks if setup is complete and guides users through configuration if needed. ### Method AL ### Signature ```al procedure RunSetup() ``` ``` -------------------------------- ### Example Request for Get bankAccounts Source: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/api-reference/v2.0/api/dynamics_bankaccount_get An example of a GET request to retrieve a bank account from the Business Central API. ```HTTP GET https://{businesscentralPrefix}/api/v2.0/companies({id})/bankAccounts({id}) ``` -------------------------------- ### SetupEmail Method Source: https://learn.microsoft.com/en-us/dynamics365/business-central/application/base-application/codeunit/o365-setup-email Sets up email configuration. Use the ForceSetup parameter to re-run the setup even if already configured. ```AL procedure SetupEmail(ForceSetup: Boolean) ``` -------------------------------- ### Get attachments request example Source: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/api-reference/v2.0/api/dynamics_attachment_get Example of an HTTP GET request to retrieve attachments for a specific parent ID. ```http GET https://{businesscentralPrefix}/api/v1.0/companies({id})/attachments?$filter=parentId eq {journalLineId} ``` -------------------------------- ### Example Request with URL and Headers Source: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/administration/cloudmigrationapi/api/dynamics_setupcloudmigration_create This example shows a complete POST request, including the full URL, content type header, and the JSON body for creating a setup cloud migration. ```http POST https://{businesscentralPrefix}/api/v1.0/companies({id})/setupCloudMigrations({id}) Content-type: application/json { "id" : "", "productId" : "", "sqlServerType" : "", "sqlConnectionString" : "", "runtimeName" : "", "runtimeKey" : "" } ``` -------------------------------- ### GetPreviousRecord Source: https://learn.microsoft.com/en-us/dynamics365/business-central/application/base-application/codeunit/microsoft.utilities.sync.dep.fld-utilities Gets the previous record. This function should be called before the update of the record is done, for example from OnBeforeModify trigger. xRec is not the previous version of the record; it is the previous record on the page. If the update was not started from a page, xRec will be the same as Rec. ```APIDOC ## GetPreviousRecord ### Description Gets the previous record. This function should be called before the update of the record is done, for example from OnBeforeModify trigger. xRec is not the previous version of the record; it is the previous record on the page. If the update was not started from a page, xRec will be the same as Rec. ### Method AL ### Signature procedure GetPreviousRecord(CurrentRecord: Variant, var PreviousRecordRef: RecordRef): Boolean ### Parameters #### Input - **CurrentRecord** (Variant) - Current record that we want to get a previous version of. #### Output - **PreviousRecordRef** (RecordRef) - Previous record. ### Returns - **Boolean** - A boolean that indicates whether the previous record exists. ``` -------------------------------- ### InitializeFromMfgSetup Method (Obsolete) Source: https://learn.microsoft.com/en-us/dynamics365/business-central/application/base-application/report/microsoft.inventory.requisition.calculate-plan---req.-wksh. Obsolete method for initializing from manufacturing setup. Use InitializeFromSetup() instead. ```AL [Obsolete(Replaced by procedure InitializeFromSetup(),27.0)] procedure InitializeFromMfgSetup() ``` -------------------------------- ### OpenSetupWindow Source: https://learn.microsoft.com/en-us/dynamics365/business-central/application/base-application/codeunit/o365-sync.-management Opens the setup window for O365 synchronization. Returns a boolean indicating success. ```APIDOC ## OpenSetupWindow ### Description Opens the setup window for O365 synchronization. ### Method AL Procedure ### Parameters None ### Returns - **Boolean**: Indicates if the setup window was opened successfully. ``` -------------------------------- ### Set up Cloud Migration (POST) Source: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/administration/cloudmigrationapi/cloud-migration-api-overview Use a POST request to create the initial cloud migration setup. This is for first-time setups. ```json POST https://api.businesscentral.dynamics.com/v2.0/{aadTenantID}/{environment name}/api/microsoft/cloudMigration/v1.0/companies({companyId})/setupCloudMigration Authorization: Bearer {token} Content-type: application/json Body: { "productId":"{ProductID}", "sqlServerType":"{SqlServerType}", "sqlConnectionString":"{SqlConnectionString}" } ``` -------------------------------- ### Example GET Request for Shipment Methods Source: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/api-reference/v2.0/api/dynamics_shipmentmethod_get An example of a GET request to retrieve a shipment method from the Business Central API. ```http GET https://{businesscentralPrefix}/api/v1.0/companies({id})/shipmentMethods({id}) ``` -------------------------------- ### SetupIsInPlace Source: https://learn.microsoft.com/en-us/dynamics365/business-central/application/base-application/codeunit/microsoft.finance.financialreports.trial-balance-mgt. Checks if the setup for the trial balance is in place. ```APIDOC ## SetupIsInPlace ### Description Checks if the setup for the trial balance is in place. ### Method AL Procedure ### Signature `procedure SetupIsInPlace(): Boolean` ### Returns #### Success Response (Boolean) - **Boolean** - Description: ``` -------------------------------- ### Example GET Request for Item Picture Source: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/api-reference/v2.0/api/dynamics_picture_get This example shows how to make a GET request to retrieve the picture details for an item. ```http GET https://{businesscentralPrefix}/api/v2.0/companies(companyId)/items(itemId)/picture ``` -------------------------------- ### Example GET item request Source: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/api-reference/v2.0/api/dynamics_item_get An example of a GET request to retrieve an item from Business Central, including the full URL. ```http GET https://graph.microsoft.com/v2.0businesscentralPrefix/companies({id})/items({id}) ``` -------------------------------- ### Writing 'Hello World' to a File Source: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/file/file-write-joker-method This example demonstrates how to write the string 'Hello World' to a file. It first checks if the file exists, then opens it for writing, writes the content, and finally closes the file. If the file does not exist, an error message is displayed. ```AL var FileName: Text; TestFile: File; begin FileName := 'C:\TestFolder\TestFile.txt'; if Exists(FileName) then begin TestFile.WriteMode(True); TestFile.Open(FileName); TestFile.Write('Hello World'); TestFile.Close; end else Message('%1 does not exit.', FileName); ``` -------------------------------- ### Suite-Setup File Example Source: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/ai-test-copilot-datasets Defines shared master data for a test suite, including actions to create locations and customers. The framework uses the 'suite_setup' content to set up data before tests run. ```yaml name: MY-AGENT-SETUP description: Shared master data for the My Agent suite. suite_setup: setup_actions: - action_type: create_location action_data: - Name: MAIN - action_type: create_customers action_data: - "No.": CUST001 Name: Validation Customer 01 - "No.": CUST002 Name: Validation Customer 02 ``` -------------------------------- ### Example GET Request for Payment Terms Source: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/api-reference/v2.0/api/dynamics_paymentterm_get An example of a GET request to retrieve a payment terms object from the Business Central API. ```bash GET https://{businesscentralPrefix}/api/v2.0/companies({id})/paymentTerms({id}) ``` -------------------------------- ### Get General Product Posting Group Request Example Source: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/api-reference/v2.0/api/dynamics_generalproductpostinggroup_get Example of the GET request to retrieve a general product posting group. ```http GET https://{businesscentralPrefix}/api/v2.0/companies({id})/generalProductPostingGroups({id}) ``` -------------------------------- ### Example GET Currency Request Source: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/api-reference/v2.0/api/dynamics_currency_get An example of a GET request to retrieve currency details, including the base URL and company/currency IDs. ```HTTP GET https://{businesscentralPrefix}/api/v2.0/companies({id})/currencies({id}) ``` -------------------------------- ### Setup Source: https://learn.microsoft.com/en-us/dynamics365/business-central/application/base-application/interface/microsoft.sales.reminder.reminder-action Sets up the reminder action. ```APIDOC ## Setup ### Description Sets up the reminder action. ### Method AL Procedure ### Signature ```al procedure Setup() ``` ``` -------------------------------- ### Get automationCompany Request Example Source: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/administration/api/dynamics_automationcompany_get An example of a GET request to retrieve an automation company, including the environment name and specific IDs. ```HTTP GET https://api.businesscentral.dynamics.com/v2.0/{environment name}/api/microsoft/automation/v2.0/companies({companyId})/automationCompanies({automationCompanyId}) ``` -------------------------------- ### Registering App Setup with Guided Experience Source: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/administration/onboarding-onboard-users-to-your-app This AL code snippet shows how to register your app's setup page as a Guided Experience Item. It uses an EventSubscriber to hook into the system's registration process, allowing users to easily find and access the setup wizard. ```AL codeunit 50100 "My App Setup" { [EventSubscriber(ObjectType::Codeunit, Codeunit::System.Environment.Configuration."Guided Experience", OnRegisterAssistedSetup, '', true, true)] local procedure InsertIntoAssistedSetupOnRegisterAssistedSetup() var GuidedExperience: Codeunit System.Environment.Configuration."Guided Experience"; IsPrimarySetup: Boolean; AssistedSetupGroup: Enum System.Environment.Configuration."Assisted Setup Group"; VideoCategory: Enum System.Media."Video Category"; ExpectedDuration: Integer; SetupShortTitle: Text[50]; HelpUrl, VideoUrl : Text[250]; SetupDescription: Text[1024]; SetupTitle: Text[2048]; begin IsPrimarySetup := true; SetupTitle := ''; SetupShortTitle := ''; SetupDescription := ''; HelpUrl := ''; VideoUrl := '