0
votes

I am trying to access the word document context from a dialog, like so:

Office.context.document.setSelectedDataAsync("Hello World!",
        function (asyncResult) {
            var error = asyncResult.error;
            if (asyncResult.status === Office.AsyncResultStatus.Failed){
                 write(error.name + ": " + error.message);
            }
        });

This does not work as setSelectedDataAsync is undefined.

In the documentation here https://dev.office.com/reference/add-ins/shared/officeui.displaydialogasync it says at the bottom under Design considerations "Do not use a dialog box to interact with a document. Use a task pane instead."

Is it not possible at all to access the complete word document context from a dialog or is it just a recommendation to not do it?

Ideally I would like to show the user a list of entries with a lot of details, from which the user then can select one and a document will be inserted into the document. Technically I could do this in a TaskPane, but there is limited space there. If possible at all I would really like to do it in a dialog (especially as I have a few other very similar requirements).

Any chance to interact with the word document in the same way as from as TaskPane?

1

1 Answers

4
votes

You can't interact with the document from a dialog.

From the documentation:

https://dev.office.com/docs/add-ins/develop/dialog-api-in-office-add-ins

The messageParent function is one of only two Office APIs that can be called in the dialog box. (The other is Office.context.requirements.isSetSupported)

So basically, all you can do from a dialog is show/collect some data and send it back to the parent via the messageParent function.

You can display all the options to the user, then send back the selected one to the parent window, and there interact with the document as required.