Build links into the current environment's client with GetUrl, not a hand-written URL
This applies only to links that open a page, report, or record in the environment the code runs in. It does not apply to:
- microsoftlayer
- styledomain
- 2examples
- 1pull request
Rule on GitHub · microsoft layer · style · BC all · tier official · derived
Description
This applies only to links that open a page, report, or record in the environment the code runs in. It does not apply to:
- Documented web client parameters appended to a
GetUrlresult. Base App appends&$filter=...&mode=Viewfor the Job Queue failure link and a filter for the Sales Documents drill-down. - A link to a different environment whose base URL comes from setup, which
GetUrlcannot target. Master Data Management builds its source-environment OData URL from"Source Environment URL". - Fixed endpoints that are not object links, such as the
OAuthLanding.htmredirect URL or a webhook callback address. - Code that deliberately points at the online service from another deployment. Base App’s
[Scope('OnPrem')]GetIntelligentCloudInsightsUrltakes the path fromGetUrland sets the host tobusinesscentral.dynamics.com. - URLs outside Business Central, such as documentation links.
Two GetUrl behaviors to know before relying on its result. A runtime error occurs “if the ClientType is set to SOAP or OData but the specified object type and ID has not been published as a web service”; checking the result for '' does not catch it. With UseFilters, Learn says filters are supported only for listed client types “when CurrenClientType is one of the ClientType mentioned. An empty string is returned otherwise.” By that wording, a call with UseFilters = true from a background or job queue session returns ''.
Within that scope, the URL depends on the host, the Microsoft Entra tenant or server instance, the environment, the company, and the object (Learn’s “Web client URL” format, https://businesscentral.dynamics.com/?company=...&page=...). GetUrl “Generates a URL for the specified client target that is based on the configuration of the server instance. If the code runs in a multitenant deployment architecture, the generated URL will automatically apply to the tenant ID of the current user.” Its signature is GetUrl(ClientType [, Company: Text] [, ObjectType] [, ObjectId: Integer] [, Record] [, UseFilters: Boolean] [, Layout: Text]); a Record “specifies which record to open”. A URL assembled from a literal host, tenant, or environment name keeps pointing at one deployment when the code runs in a sandbox, another tenant, or on-premises, and has to encode the company name and filters itself.
Best Practice
Call GetUrl with the company, object type, object ID, and, for a specific record, the record. Base App’s "Page Management".GetWebUrl sets a record filter, resolves the page for the record’s table, and calls GetUrl with the RecordRef; its notification email builds the settings link with GetUrl too. Both pass ClientType::Web; Learn says to pass ClientType::Current when the URL should depend on the client the user is accessing it from. See sample: build-client-links-with-geturl.good.al.
Anti Pattern
Code builds a link to a page, report, or record in the environment it runs in by concatenating or formatting a literal Business Central host, tenant, or environment with ?company=, &page=, &report=, or &bookmark= parameters. See sample: build-client-links-with-geturl.bad.al.
References
- System.GetUrl method: signature, tenant handling,
Current, the SOAP/OData runtime error, andUseFilters. Web client URL: hostname, Entra tenant, environment,company,page,report,bookmark, andfilter. - PageManagement.Codeunit.al (
GetWebUrl, lines 525-534) and NotificationEmail.Report.al (CreateSettingsLink, 182-191). - Appended parameters: JobQueueSendNotification.Codeunit.al (
SetURL, 196-212) and SalesDocuments.Page.al (65-69). - Carve-outs: MDMHttpSourceTransport.Codeunit.al (41, 176-182), ImportConsolidationFromAPI.Codeunit.al (68), ShpfySyncShopLocations.Codeunit.al (29), IntelligentCloudManagement.Codeunit.al (15-28).
- Create URLs to NAV Clients, AL Guidelines (NAV Design Patterns) article by Mike Borg Cardona and Bogdana Botez at Microsoft Development Center Copenhagen. It says
GETURLreturns an empty string for invalid parameters (line 103); current Learn documents the runtime error above for unpublished SOAP/OData objects, so follow Learn.
Examples
Changed by
From microsoft/BCQuality at a4593a1, MIT License, Copyright (c) 2026 Microsoft Corporation (license).