2

My question is just opposite to scenario asked here

How we can fetch SingleValueExtendedProperties which is set through graph API and then wanted to retrieve same property in office Add-in.

Set: Code something similar below

var requestBody = new HttpRequestMessage(action, requestUrl) { Content = new StringContent("{'SingleValueExtendedProperties': [{'PropertyId':'String {66f5a359-4659-4830-9070-00047ec6ac6e} Name Color','Value':'Green'}]}", Encoding.UTF8, "application/json") };

Read: I tried used all combination to get property value but getting undefined results

    const item = Office.context.mailbox.item;
    item.loadCustomPropertiesAsync((result) => {
        const props = result.value;
        const testProp = props.get("Color");
        console.log("Color", testProp);
    });

Could anybody help me getting property value in office 365 Add-in.

Manoj Patil
  • 970
  • 1
  • 10
  • 19

1 Answers1

2

You won't be able to read the properties the way your trying because the property you created isn't compatible with the Mail App format eg this is documented in https://msdn.microsoft.com/en-us/library/hh968549(v=exchg.80).aspx (basically the properties themselves contain the ClientId of the app they belong to so when you call loadCustomPropertiesAsync it knows which properties to get). The method you used in the Graph API just created a normal Named Property https://msdn.microsoft.com/en-us/library/office/ff960427.aspx . You could get this property in a Mail app but only using EWS (eg your app would need ReadItem permission) and make a GetItem Request using makeEwsRequestAsync. Alternatively you should be able to make the Graph API write the properties in a format that the MailApp would read in loadCustomPropertiesAsync (this requires writing more then one property if you follow the documentation).

Additional

If you want to set the property using the Graph API on a Message where there have been no other Mail Apps that have set a property you would use

"SingleValueExtendedProperties": [
{
"PropertyId":"String 00020329-0000-0000-C000-000000000046 Name cecp-propertyNames",
"Value":"cecp-51248e59-f341-4b4a-a81a-a418f8d3b179;"
 }
,{
"PropertyId":"String 00020329-0000-0000-C000-000000000046 Name cecp-51248e59-f341-4b4a-a81a-a418f8d3b179",
"Value":"{\"mail_note\":\"Whats the point\"}"
 }
]
}

The Guid in this example 51248e59-f341-4b4a-a81a-a418f8d3b179 should match the UUID from your MailApps manifest file eg

<OfficeApp xmlns="http://schemas.microsoft.com/office/appforoffice/1.1" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:type="MailApp">
    <!-- Id is a unique UUID for the mail app -->
    <Id>51248e59-f341-4b4a-a81a-a418f8d3b179</Id>

If other Mail apps have set properties on the Message then you would need modify the first property to append your MailApp UUID into that property value. For example if your mail app UUID was 81a51297-e77e-4fae-a07f-af546013aeac and the message already had the values as above you would modify the property like

"cecp-51248e59-f341-4b4a-a81a-a418f8d3b179;cecp-81a51297-e77e-4fae-a07f-af546013aeac;"

Glen Scales
  • 20,495
  • 1
  • 20
  • 23
  • Thanks! @Glen, does this means I can read in prop value in add-in but it would need more efforts to write it correctly in graph API? and if possible could you please elaborate how? – Manoj Patil May 24 '17 at 11:07