OfficeJs

时间:2017-12-01 19:12:25

标签: jquery outlook-addin office-js

我刚刚在OfficeJ中遇到removeAttachmentAsync()的一些意外行为。直到最近(几周),功能一致并适用于我们的案例,然后我们似乎看到了一些奇怪的事情发生。

所以我们有一个按钮,可以通过addFileAttachmentAsync()在撰写页面上添加附件,然后我们将attachment_id保存到会话中供将来使用,然后按钮逻辑反转使用removeAttachmentAsync()使用会话中保存的attachment_id删除所述附件。请记住,当我们添加附件时,我们会等待并确认附件已完全添加,然后用户才能执行任何其他操作。然后,用户可以选择转到设置页面。

验证附件是否已成功添加:

status: "succeeded"
value: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxx" // ${attachment_id}

这是事情变得有趣的地方,如果用户添加附件然后转到设置页面,然后返回到我们的撰写页面,并选择删除附件我们收到此错误但OfficeJs正在删除附件:< / p>

error: Object { name: "AttachmentDeletedBeforeUploadCompletes",
   message: "The user removed the attachment before upload has completed.",
   code: 9006 }
   status: "failed"
   value: null

但以下是OfficeJS针对Exchange服务器执行的DeleteAttachment操作:

网址:https://exchange.server.com/owa/service.svc?action=DeleteAttachment&ID=-481&AC=1 响应:

{
    "Body":{
        "ResponseMessages":{
            "Items":[
                {
                    "__type":"DeleteAttachmentResponseMessage:#Exchange",
                    "ResponseCode":"NoError",
                    "ResponseClass":"Success",
                    "RootItemId":{
                        "RootItemChangeKey":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                        "RootItemId":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx="
                    }
                }
            ]
        }
    }
}

此行为不一致,Exchange服务器表示成功,而OfficeJs表示失败。

以下是删除附件的代码:

      function remove() {
            $.ajax({
              url: "/getattachment",
              dataType: 'json',
              cache: false
            }).always(function(res) {
              if(res.id) {
                Office.context.mailbox.item.removeAttachmentAsync(res.id,{asyncContext: null}, function (asyncResult) {
                    // Display the result to the user
                    if (asyncResult.status == Office.AsyncResultStatus.Succeeded) {
                      if (typeof Office.context.mailbox.item.notificationMessages === 'undefined') {
                        sidepane_status('success', 'Attachment removed.');
                      } else {
                        update_status('encryption-off', 'Attachment removed..');
                      }
                      attachment_id = null;
                    } else {
                      sidepane_status('error', 'Unable to remove attachment: ' + asyncResult.error.message);
                    }
                  }
                );
              } else {
                sidepane_status('error', 'Unable to remove attachment: ' + asyncResult.error.message);
              }
            });
          }

在MS文档中,我看到:

“在Outlook Web App和OWA for Devices中,附件标识符仅在同一会话中有效。当用户关闭应用程序时,或者如果用户开始以内嵌形式撰写并随后弹出内联表单继续在一个单独的窗口中。“

但在这种情况下,用户没有关闭应用程序,仍然使用相同的会话,而不是组成内联表单。

任何人都知道最近可能发生的变化或对可能发生的事情的任何见解?

TLDR;被称为removeAttachmentAsync()的附件被移除,但OfficeJs返回失败,因为“用户在上传完成之前删除了附件。”。

更新1:附件代码

function add() {
  $.ajax({
    url: "/attachment",
    dataType: 'json',
    cache: false
  }).done(function(response) {
    if(typeof response.attachment_name !== "undefined" && typeof response.attachment_url !== 'undefined') {
      Office.context.mailbox.item.addFileAttachmentAsync(response.attachment_url, response.attachment_name, { asyncContext: null }, function(asyncResult) {
          if(asyncResult.status == Office.AsyncResultStatus.Succeeded) {
            if(typeof Office.context.mailbox.item.notificationMessages === 'undefined') {
              sidepane_status('success', 'Attachment successfully added');
            } else {
              update_status('encryption-on', 'Attachment successfully added.');
            }
            attachment_id = asyncResult.value;
            $.ajax({
              url: "/saveattachment/" + attachment_id,
              dataType: 'json',
              cache: false
            }).always(function() {
              // Hide an Element
            });
          } else {
            sidepane_status('error', 'Unable to add attachment: ' + asyncResult.error.message);
          }
        }
      );
    } else {
      sidepane_status('error', 'Unable to retrieve attachment information');
    }
  });
}

请记住,用户添加add()附件,我们保存附件ID,用户通过超链接转到新页面并返回另一个超链接。由于我们保存了附件ID,因此我们使用它来删除附件remove()

0 个答案:

没有答案
相关问题