• Home /
  • Blog /
  • Office Add-in: Dialog API's messageParent not working
Office Add In Dialog Messaging API

Office Add-in: Dialog API's messageParent not working

When building an Outlook plugin, I need a way to communicate between windows. The way Microsoft provides is to use Office messaging API. On your host you need to open a dialog and subscribe to dialog evens the following way:

Office.context.ui.displayDialogAsync(fullUrl,
    {
        height: 60,
        width: 20,
        displayInIframe: false
    }, function (asyncResult) {
        if (asyncResult.status === Office.AsyncResultStatus.Failed) {
                //showNotification(asyncResult.error.code = ": " + asyncResult.error.message);
            } else {
            dialog = asyncResult.value;
            dialog.addEventHandler(Office.EventType.DialogMessageReceived, processMessage);
            dialog.addEventHandler(Office.EventType.DialogEventReceived, processDialogEvent);
        }
    });
            

The following code subscribe host to events which Pop up sends back, for example, "close" event, so your host may close popup

dialog.addEventHandler(Office.EventType.DialogMessageReceived, processMessage);
        

Inside of the popup, you can send messages back to host using the following code:

var messageObject = { messageType: "signinSuccess" };
var jsonMessage = JSON.stringify(messageObject);
Office.context.ui.messageParent(jsonMessage);
            

That all suppose to work, but it does not because of old and misleading documentation and samples provided by Microsoft. When the popup sends message to host, nothing happens, but if you close the popup window, you are going to receive "dialog closed" event.

After some debugging of Office Javascript API, I found that all URLs in the manifest files should have prefix https://. As soon as I have that prefix, it all starts working fine.


  <AppDomains>
    <AppDomain>https://app.polarcrm.com</AppDomain>
    <AppDomain>https://localhost:44321</AppDomain>
  </AppDomains>
            

Outlook add-in dialog messaging messageParent does not work

Comments

Yaplex - Freelance developer - white logo on black background

Yaplex is a custom software development company co-founded by full-stack .NET Software developer Alex Shapovalov who lives in Mississauga, ON and provides software development services in Mississauga and GTA.

Contact Information

Mississauga, ON, Canada
Phone: +1 647 328 3809
Email: alex@yaplex.com