BCQuality rule · styleAL Developmentofficial - Microsoftderived - from the source, no model text

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:

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 GetUrl result. Base App appends &$filter=...&mode=View for 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 GetUrl cannot 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.htm redirect URL or a webhook callback address.
  • Code that deliberately points at the online service from another deployment. Base App’s [Scope('OnPrem')] GetIntelligentCloudInsightsUrl takes the path from GetUrl and sets the host to businesscentral.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

Examples

Changed by


From microsoft/BCQuality at a4593a1, MIT License, Copyright (c) 2026 Microsoft Corporation (license).