1

I am currently setting custom ExtendedProperties on a CalendarFolder using EWS Managed API (C#):

myCalendar.SetExtendedProperty(customExtendedProperty, true);

I can also use the Managed API to load those settings when I bind the CalendarFolder:

var myCalendar = CalendarFolder.Bind(service, folderId, requestedPropertySet);

I would next like to read these same ExtendedProperties, but from an Outlook Add-In using the Office JavaScript libraries.

From the looks of the the Outlook library does not expose any methods off of Office.context.item to access the ExtendedProperties.

Are there methods in the library that allow me to access this? If not, can I use the schema approach which has the GUID in the URL path ("http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/yourProp")?

Andy T
  • 10,223
  • 5
  • 53
  • 95

2 Answers2

4

To access your own custom properties on a folder in Addin you need to use the makeEwsRequestAsync https://dev.outlook.com/reference/add-ins/Office.context.mailbox.html#makeEwsRequestAsync to do a GetFolder in your Addin. To get the correct SOAP message just enabling tracing in you EWS Managed API code which will output the SOAP used https://msdn.microsoft.com/en-us/library/office/dn495632(v=exchg.150).aspx which you can these transpose. The one thing to be aware of is the security requirements for making a makeEwsRequestAsync in your app eg ReadWriteMailbox http://dev.office.com/docs/add-ins/outlook/understanding-outlook-add-in-permissions

Glen Scales
  • 20,495
  • 1
  • 20
  • 23
  • 1
    I had no idea there was a way to profile the SOAP messages that get sent. That was the missing piece. Thank you! – Andy T Aug 17 '16 at 14:46
2

As of now (July 2018), the preferred way to access custom ExtendedProperties when writing an Outlook add-in is to use the ExtendedProperties REST API.

There is some sample code showing how to use the API with the Office add-in JavaScript library, available from Office Dev Center.

To use the API, you need to get an auth token from the current Outlook mailbox. This can be done using the Office.context.mailbox.getCallbackTokenAsync() method, with keyword parameter {isRest: true}.You should also use the Office.context.mailbox.restUrl property to get the correct base URL for the API call.

There are a few ways to actually make a REST API call from JavaScript, but the simplest way to do it clientside is with an AJAX call. In your example, this would look like:

const getMessageUrl = Office.context.mailbox.restUrl
  + "/v2.0/me/mailFolders/" + <folder id> + "?"
  + "$expand=singleValueExtendedProperties"
  + "($filter=PropertyId eq '<property id>')";

$.ajax({
  url: getMessageUrl,
  datatype: 'json',
  headers: {'Authorization': 'Bearer ' + <auth token>}
}).then(item => {
  // your code here
})

If you have a GUID for your property, then <property id> will look like the following:

"String {00020329-0000-0000-C000-000000000046} Name yourProp"

If you're like me and were trying to access a property that predates the GUID rules, then your <property id> may look like this:

"String 0x007D"
nupanick
  • 754
  • 8
  • 13