stopyoukid
stopyoukid

Reputation: 182

Office Dialog API send message to child dialog

We would like to use the Dialog API for some extra operations which are better suited to a larger work area. We already have the ability via the API to message the parent from the dialog (Office.context.ui.messageParent), however we would also like the ability to directly message the dialog, like a sendMessage function, for example:

var dialog;
Office.context.ui.displayDialogAsync('https://myDomain/myDialog.html', function (asyncResult) {
    if (asyncResult.status === "failed") { 
        showNotification(asynceResult.error.code = ": " + asyncResult.error.message); 
    } else {
        dialog = asyncResult.value;
        dialog.addEventHandler(Office.EventType.DialogMessageReceived, processMessage);
        dialog.sendMessage({ /* my payload */ }); //???
    }
}); 

There are a couple of options to pass data from the parent to the child:

  1. query string: displayDialogAsync(myUrl + "?myMessage=...", function...)
  2. localStorage (if on the same domain): localStorage.setItem("DIALOG_MESSAGE", myMessage)

However, both of these can only really be used on initialization of the dialog, they do not provide a nice way to do asynchronous messaging.

Upvotes: 4

Views: 2086

Answers (3)

William Worner
William Worner

Reputation: 7

You can use this in parrent before usedisplayDialog:

localStorage.setItem("clientID", "15963ac5-314f-4d9b-b5a1-ccb2f1aea248");

And then in your JavaScript file:

var clientID = localStorage.getItem("clientID");

Upvotes: 0

Rick Kirkham
Rick Kirkham

Reputation: 9659

That is a popular request (and a good idea), but it is not supported yet. Please go to Office Dev User Voice and vote up the "Improve Custom Dialog" suggestion there or create a new suggestion of your own.

Upvotes: 4

Related Questions