2

Is there an api to access get all available values async in Office.js, specifically Office.context.mailbox.item in Outlook?

I do not see anything in the docs.

I need to capture 10 or so fields, and to date have only implemented with callbacks, e.g.

var ITEM = Office.context.mailbox.item;
var wrapper =  //fn to parse results and call next field getAsync as cb
ITEM.end.getAsync(wrapper);
jhpratt
  • 6,841
  • 16
  • 40
  • 50
nrako
  • 2,952
  • 17
  • 30

2 Answers2

1

The documentation reference you have provided stated the Office.context.mailbox.item is the namespace. The namespace don't have the method which would enumerate all other methods in the namespace and return some consolidated result, instead you would use specific method, get the result and move to the next method you are interested in. This is all Office.js API offered for the item.

If you need to get several item properties at once, you may look at EWS request support of Office.js API by calling to Office.context.mailbox.makeEwsRequestAsync. Inside your XML request you may specify fields you are interested in and retrieve them with one request/response. Refer to Call web services from an Outlook add-in article for more information.

Yet another option to get several item properties at once is to Use the Outlook REST APIs from an Outlook add-in

Slava Ivanov
  • 6,666
  • 2
  • 23
  • 34
  • I don't want to make any requests across the wire, just grab the current state of the record from the client without having deeply nested callbacks. As such, it would appear that this is not feasible. Thanks for the note. – nrako Jan 07 '19 at 23:12
1

I solved this with jQuery.when

const dStart = $.Deferred()
const dEnd = $.Deferred()

Office.context.mailbox.item.start.getAsync((res) => {
  // check for errors and fetch result
  dStart.resolve()
})

Office.context.mailbox.item.end.getAsync((res) => {
  // check for errors and fetch result
  dEnd.resolve()
})

$.when(dStart, dEnd).done(function() {
  // will fire when d1 and d2 are both resolved OR rejected
}

If you don't want jQuery you can use promises and Promise.all

João Pimentel Ferreira
  • 14,289
  • 10
  • 80
  • 109