Get the BC tenant ID using javascript

martyomartyo Member Posts: 1


I have built a Busincess Central extension add-in that uses javascript to read the tenant ID and company from the URL and passes those values to the app (which is displayed in an iframe).

var widget = document.createElement("iframe");
var path = window.location.pathname.split("/");
var tenant = path[1];
var sandbox = path.length > 2 ? "true" : "false";
var company = new URL(document.location.href).searchParams.get("company");
widget.setAttribute("src", "https://widget.popdock.com/Embed/BusinessCentral/" + tenant + "?sandbox=" + sandbox + "&company=" + company);

This doesn't always work though in all scenarios. Business Central offers multiple login paths. Some of these paths don't display a tenant ID in the URL, which causes an error. I know I can get a tenant ID from AL but cannot pass that back as a parameter.

Is there a more reliable way to get the tenant ID using javascript than reading it from the URL?


Sign In or Register to comment.