none
Updates to Office API breaks existing code to get attachments of an Outlook item from server RRS feed

  • Question

  • Today, we observed an issue with Outlook API where following object mailbox.item.attachments[i].$0_0 was shown as undefined,

          // Format the attachment details for sending.
          for (var i = 0; i < mailbox.item.attachments.length; i++) {
            serviceRequest.attachments[i] = JSON.parse(JSON.stringify(mailbox.item.attachments[i].$0_0));
          }

    Above code is taken from https://msdn.microsoft.com/en-in/library/office/dn148008.aspx  

    On investigation, we observed that Outlook API is no longer returning $0_0 in Office.context.mailbox.item.attachments, which breaks above code. Instead of $0_0, Outlook API is returning _data$p$0.

    Hence, changing the above code to use following works fine but I want to understand whether the change we are doing is fine or we are expecting any more changes in the Office API?

    Old property: Office.context.mailbox.item.attachments[i].$0_0

    New property: Office.context.mailbox.item.attachments[i]._data$p$0

    Also, do we have any blog, where the updates to https://appsforoffice.microsoft.com/lib/1/hosted/Office.js are notified.



    Tuesday, March 22, 2016 5:56 AM

Answers

  • Hi,

    Thanks for the detail information for this issue. I am also could reproduce this issue too.

    To fix this issue, I suggest that you use property that published by the official document. And here is the modifying for your reference:

      function makeServiceRequest() {
    
    
    
            Office.context.mailbox.getCallbackTokenAsync(function (rs) {
                // Initialize a context object for the add-in.
                //   Set the fields that are used on the request
                //   object to default values.
                var serviceRequest = new Object();
                //serviceRequest.attachmentToken = "";
                //getAttachmentToken(serviceRequest);
                serviceRequest.ewsUrl = Office.context.mailbox.ewsUrl;
                serviceRequest.attachments = new Array();
    
                serviceRequest.attachmentToken = rs.value;
                // Format the attachment details for sending.
                for (var i = 0; i < Office.context.mailbox.item.attachments.length; i++) {
                    //serviceRequest.attachments[i] = JSON.parse(JSON.stringify(Office.context.mailbox.item.attachments[i]._data$p$0));
                  
                    //serviceRequest.attachments[i] = JSON.parse(JSON.stringify(Office.context.mailbox.item.attachments[i]));
    
                    var att = { "attachmentType": Office.context.mailbox.item.attachments[i].attachmentType, "contentType": Office.context.mailbox.item.attachments[i].contentType, "id": Office.context.mailbox.item.attachments[i].id, "isInline": Office.context.mailbox.item.attachments[i].isInline, "name": Office.context.mailbox.item.attachments[i].name, "size": Office.context.mailbox.item.attachments[i].size }
                    serviceRequest.attachments[i] = JSON.parse(JSON.stringify(att));
                }
    
                $.ajax({
                    url: '../../api/Attachment',
                    type: 'POST',
                    data: JSON.stringify(serviceRequest),
                    contentType: 'application/json;charset=utf-8'
                }).done(function (response) {
                    if (!response.isError) {
                        var names = "<h2>Attachments processed using " +
                                      serviceRequest.service +
                                      ": " +
                                      response.attachmentsProcessed +
                                      "</h2>";
                        for (i = 0; i < response.attachmentNames.length; i++) {
                            names += response.attachmentNames[i] + "<br />";
                        }
                        document.getElementById("names").innerHTML = names;
                    } else {
                        app.showNotification("Runtime error", response.message);
                    }
                }).fail(function (status) {
    
                }).always(function () {
                    $('.disable-while-sending').prop('disabled', false);
                })
    
            });
        }

    Regards & Fei 


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, March 30, 2016 9:16 AM
    Moderator

All replies

  • Hi NikhiDarjee,

    What did you mean that "$0_0)"? As far as I know, the AttachmentDetails does't have this property. Please refer to the link below about more detail about this object:
    https://dev.outlook.com/reference/add-ins/simple-types.html#AttachmentDetails

    In addition, to make the product stable, I suggest that you use the property and method published by the document.

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, March 23, 2016 6:34 AM
    Moderator
  • Hi Fei Xue,

    Thanks for your response. By $0_0, I am referring to the property used in the code sample provided in the following MSDN article in the "Send attachment information to the remote service" section.

    MSDN Article: https://msdn.microsoft.com/en-in/library/office/dn148008.aspx

    Refer to the JavaScript code sample below from above MSDN article, please note the property $0_0 used on line number 4 below,  

    function makeServiceRequest() {
          // Format the attachment details for sending.
          for (var i = 0; i < mailbox.item.attachments.length; i++) {
            serviceRequest.attachments[i] = JSON.parse(JSON.stringify(mailbox.item.attachments[i].$0_0));
          }
    
          $.ajax({
            url: '../../api/Default',
            type: 'POST',
            data: JSON.stringify(serviceRequest),
            contentType: 'application/json;charset=utf-8'
          }).done(function (response) {
            if (!response.isError) {
              var names = "<h2>Attachments processed using " +
                            serviceRequest.service +
                            ": " +
                            response.attachmentsProcessed +
                            "</h2>";
              for (i = 0; i < response.attachmentNames.length; i++) {
                names += response.attachmentNames[i] + "<br />";
              }
              document.getElementById("names").innerHTML = names;
            } else {
              app.showNotification("Runtime error", response.message);
            }
          }).fail(function (status) {
    
          }).always(function () {
            $('.disable-while-sending').prop('disabled', false);
          })
        };


    Wednesday, March 23, 2016 2:26 PM
  • Hi,

    Thanks for the detail information for this issue. I am also could reproduce this issue too.

    To fix this issue, I suggest that you use property that published by the official document. And here is the modifying for your reference:

      function makeServiceRequest() {
    
    
    
            Office.context.mailbox.getCallbackTokenAsync(function (rs) {
                // Initialize a context object for the add-in.
                //   Set the fields that are used on the request
                //   object to default values.
                var serviceRequest = new Object();
                //serviceRequest.attachmentToken = "";
                //getAttachmentToken(serviceRequest);
                serviceRequest.ewsUrl = Office.context.mailbox.ewsUrl;
                serviceRequest.attachments = new Array();
    
                serviceRequest.attachmentToken = rs.value;
                // Format the attachment details for sending.
                for (var i = 0; i < Office.context.mailbox.item.attachments.length; i++) {
                    //serviceRequest.attachments[i] = JSON.parse(JSON.stringify(Office.context.mailbox.item.attachments[i]._data$p$0));
                  
                    //serviceRequest.attachments[i] = JSON.parse(JSON.stringify(Office.context.mailbox.item.attachments[i]));
    
                    var att = { "attachmentType": Office.context.mailbox.item.attachments[i].attachmentType, "contentType": Office.context.mailbox.item.attachments[i].contentType, "id": Office.context.mailbox.item.attachments[i].id, "isInline": Office.context.mailbox.item.attachments[i].isInline, "name": Office.context.mailbox.item.attachments[i].name, "size": Office.context.mailbox.item.attachments[i].size }
                    serviceRequest.attachments[i] = JSON.parse(JSON.stringify(att));
                }
    
                $.ajax({
                    url: '../../api/Attachment',
                    type: 'POST',
                    data: JSON.stringify(serviceRequest),
                    contentType: 'application/json;charset=utf-8'
                }).done(function (response) {
                    if (!response.isError) {
                        var names = "<h2>Attachments processed using " +
                                      serviceRequest.service +
                                      ": " +
                                      response.attachmentsProcessed +
                                      "</h2>";
                        for (i = 0; i < response.attachmentNames.length; i++) {
                            names += response.attachmentNames[i] + "<br />";
                        }
                        document.getElementById("names").innerHTML = names;
                    } else {
                        app.showNotification("Runtime error", response.message);
                    }
                }).fail(function (status) {
    
                }).always(function () {
                    $('.disable-while-sending').prop('disabled', false);
                })
    
            });
        }

    Regards & Fei 


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, March 30, 2016 9:16 AM
    Moderator