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

Load packaged control add-in resources with credentialed AJAX

JavaScript in a Business Central control add-in can load a static resource from its extension package with AJAX, but the request needs the Business Central context and cookies.

Rule on GitHub · microsoft layer · ui · BC all · tier official · derived

Description

JavaScript in a Business Central control add-in can load a static resource from its extension package with AJAX, but the request needs the Business Central context and cookies. Set xhrFields.withCredentials = true; shorthand calls such as $.get omit that setting and can work during development yet fail in production.

Best Practice

Use an AJAX form that explicitly enables withCredentials whenever a control add-in requests a packaged static resource. Keep this rule scoped to resources served from the add-in package; it is not generic advice to attach credentials to arbitrary external requests.

See sample: control-addin-package-resource-ajax-needs-withcredentials.good.js.

Anti Pattern

Using $.get(url) or an XMLHttpRequest without withCredentials = true to retrieve package content. The request can lack the context and cookies required by the Business Central service.

See sample: control-addin-package-resource-ajax-needs-withcredentials.bad.js.

Source

Control add-in object: Loading static resources using AJAX requests.

Changed by


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