Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Office js 回调函数未正确执行-Outlook加载项_Office Js_Outlook Addin_Office Addins - Fatal编程技术网

Office js 回调函数未正确执行-Outlook加载项

Office js 回调函数未正确执行-Outlook加载项,office-js,outlook-addin,office-addins,Office Js,Outlook Addin,Office Addins,我试图创建一个Outlook加载项用于测试,但我遇到了一个奇怪的行为。我在XML清单中声明了以下键: <FunctionFile resid="functionFile" /> <Action xsi:type="ExecuteFunction"> <FunctionName>myEntryPoint</FunctionName> </Action> 事实上,displayNewMes

我试图创建一个Outlook加载项用于测试,但我遇到了一个奇怪的行为。我在XML清单中声明了以下键:

<FunctionFile resid="functionFile" />

<Action xsi:type="ExecuteFunction">
    <FunctionName>myEntryPoint</FunctionName>
</Action>
事实上,displayNewMessageFormAsync方法是执行的,而不是回调(console.log(result)

如果我将该代码放在“Office.initialize”函数中,则会执行回调函数


有什么想法吗?

关于Outlook加载项团队的评论-MSFT:

在调用displayNewMessageFormAsync()之后,您正在调用event.completed()。这意味着回调不能保证运行。您可以尝试将全局变量设置为event,并在回调中调用event.completed()。或者通过asyncContext传递事件

我修改了代码以在asyncContext中传递事件:

function myEntryPoint(event) {
    Office.context.mailbox.displayNewMessageFormAsync({
        toRecipients: ["firstname.name@email.com"],
        subject: "Test Subject",
        htmlBody: "Internet headers: ",
        }, 
        { asyncContext : event }, 
        function (result) {
             console.log(result);
             event.completed();
        }
    );
}

它起作用了!谢谢。

您在哪个站台?(outlookdesktop、OWA、Mac等)这些版本的版本号也很好。您的代码中可能有竞争条件(这可能取决于平台)。在调用displayNewMessageFormAsync()之后,您正在调用event.completed()。这意味着回调不能保证运行。您可以尝试将全局变量设置为event,并在回调中调用event.completed()。或者通过asyncContext传递事件。我必须问这个问题-
{//Nothing here}
或者
{/*Nothing here*/}
你能告诉我们你在构建平台时使用的是什么吗?@StefanWang:你说得对,我只在这里写了评论,我的代码中没有它。@OutlookAdd insTeam MSFT:我在OutlookWebApp(20210103002.04)上运行外接程序。我使用的是Windows 10 1809(我知道这很遗憾),我使用Visual Studio 2019 16.8.3构建代码。
function myEntryPoint(event) {
    Office.context.mailbox.displayNewMessageFormAsync({
        toRecipients: ["firstname.name@email.com"],
        subject: "Test Subject",
        htmlBody: "Internet headers: ",
        }, 
        { asyncContext : event }, 
        function (result) {
             console.log(result);
             event.completed();
        }
    );
}