How to get working Dialog API of OfficeJS API with Outlook 2016 desktop client

◇◆丶佛笑我妖孽 提交于 2019-12-10 06:28:55

问题


I developed a outlook add-in which using OfficeJS API and want to implement OAuth within app, also API Documnetation says Outlook 2016(Desktop) supports requirements set 1.1, 1.2, 1.3 & 1.4 but in my case it remains silent not even throws an error. While running working dialog api sample for word add-in i am getting JavaScript run-time error: Unable to get property 'displayDialogAsync' of undefined or null reference.

I am using Microsoft Office Professional Plus 2016.

Code I wrote to launch a dialog is below:

dialogTest() {
        const url = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?response_type=....";
        Office.context.ui.displayDialogAsync(url, { width: 15, height: 27, requireHTTPS: true }, function (asyncResult) {
            if (asyncResult.status !== Office.AsyncResultStatus.Succeeded) {
                // TODO: Handle error.
                return;
            }

            // Get the dialog and register event handlers.
            var dialog = asyncResult.value;
            dialog.addEventHandler(Microsoft.Office.WebExtension.EventType.DialogMessageReceived, function (asyncResult) {
                if (asyncResult.type !== Microsoft.Office.WebExtension.EventType.DialogMessageReceived) {
                    // TODO: Handle unknown message.
                    return;
                }

                // Parse the message.
                var data = JSON.parse(asyncResult.message);
                console.log('Hello #Office365Dev', data.name);

                // TODO: Do something with the data.

                // We got our data, time to close the dialog.
                dialog.close();
            });
        });
    }

回答1:


Looks like ui member of Office.context is not defined or Office.js is not loaded correctly. Try to review these first:

  • Is Office.js javascript loaded correctly?
  • Does Office.initialize callback well set and executed before you do something?
  • What is your Outlook Desktop 2016 version?

Edit: discussing with Microsoft engineer on June 2016 (this is no official statement). The supported builds for dialogAPI is Office for Windows Desktop 2016 (build 16.0.6741.0000 or above). This may change.

  • What is the result of this piece of code var result = Office.context.requirements.isSetSupported('DialogAPI', '1.4');


来源:https://stackoverflow.com/questions/41259110/how-to-get-working-dialog-api-of-officejs-api-with-outlook-2016-desktop-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!