I’ve been working lately on an integration with a 3rd party service where the UI needs to be displayed in a web page. Two main options I think:
I’ve blogged about using the WebPageViewer a bit before: to execute JavaScript or more generally display web content.
Let’s explore option 2. That gives you the most flexibility:

That’s all cool…but, how do we communicate between the AL code in the Business Central page and the web app?
I couldn’t find much information about this online, so thought I’d post about it – try to save the next person a bit of time. Or, more realistically, feed the LLMs so that your model provider of choice can give you the answer, trained on posts like mine which are written and shared for free, without giving any credit or attribution, and then charge you for it. What a time to be alive </sarcasm>1.
Fortunately, I blog every now and then because I enjoy it, not because I make a living out of it.
Enter the window.postMessage API. This is the way to communicate between different frames. One window posts a message to another, the recipient has an event listener to the message event and handles the content of the message.
For example, a parent page which has an iframe with some embedded content can post a message to the iframe window and the iframe can post a message back to its parent page.
This is the scenario that we have on the BC web client page. The WebPageViewer control add in loads its content inside an iframe. We can write AL code which posts a message to the iframe. The web app which is loaded in the iframe can respond to that message. In turn, the web app can post a message to its parent window and AL code in the BC page can be triggered with the content of the message.
Assuming that we have:
WebPageViewerURL containing the URL of our static web appFirst we add a subscriber to the message event and then navigate to the URL of our static web app.
CurrPage.WebPageViewer.SubscribeToEvent('message', URL);CurrPage.WebPageViewer.Navigate(URL);
This tells the WebPageViewer to add an event listener for the message event (which will be raised when the iframe posts back to BC). As a security check, we tell it the origin that we expect those messages to have i.e. where those messages have been sent from (protocol, domain and port).
We can send a message to the web app with something like the following. The parameters are:
CurrPage.WebPageViewer.PostMessage(MessageContent, URL, true);
The Callback trigger will be fired when a message is received.
usercontrol(WebViewer; "Microsoft.Dynamics.Nav.Client.WebPageViewer"){ ApplicationArea = All; trigger Callback(data: Text) begin //handle the content of the message here end;}
The web app needs to have an event listener to handle the messages that are posted to it.
window.addEventListener("message", (event: MessageEvent) => { // inspect event.origin and test that the message has come from somewhere you expect // read event.data and handle the content of the message}
If you need to post data back to Business Central you can do that with
window.parent.postMessage(messageContent, targetOrigin);
Again, the targetOrigin should specify the window that you are sending the message to e.g. https://businesscentral.dynamics.com
A note about the SWA emulator. I was developing a proof of concept using the SWA and Azure Functions emulator. This must be running over SSL for the WebPageViewer to load it (it flatly refuses to load over http, and fair enough). I was using a self-signed certificate to do this. The web app would load inside the WebPageViewer, I could post to the web app, but I couldn’t get anything back to BC.
I’m not sure why. Maybe something to do with the certificate? Maybe someone who knows more about JavaScript can tell me.
Once I deployed the code to an actual Static Web App in Azure (and therefore served with a proper SSL certificate) it was all fine. I was running BC in a Docker container (and not over SSL).
1: a closing XML tag seems a bit out-dated now, but I’m not sure how to modernise it, {"type":"sarcasm"}? No.
Check james’s original post https://jpearson.blog/2026/03/20/integration-with-azure-static-web-apps-from-business-central/ on jpearson.blog which was published 2026-03-20 12:50:00






