I am getting itemId
of a mail item after saveAsync
in compose mode.
Once mail item is sent, item Id
coming in Office.context.mailbox.item.itemId
is different than what is given in compose mode.
Code used for getting itemId
in compose mode:
var itemId = Office.context.mailbox.item.itemId;
if (itemId === null || itemId == undefined) {
Office.context.mailbox.item.saveAsync(function (result) {
itemId = result.value;
});
}
After the email is sent, I verified email's itemId
from sent box using:
`Office.context.mailbox.item.itemId`
to my surprise it is different.
According to the documentation, the itemId
should be the same:
The
itemId
property is not available in compose mode. If an item identifier is required, thesaveAsync
method can be used to save the item to the store, which will return the item identifier in theAsyncResult.value
parameter in the callback function.
What I am doing wrong?
First it is important to understand that an item's
itemId
is not a static value. The ID will change whenever an item is moved around in Exchange. From the EWS documentation:As to why this is happening, it is because
saveAsync
will result in the email being saved to the Drafts folder. When it is sent the item first moved to the Outbox and then into the Sent Items folder. Each of those folder changes (Drafts, Outbox, and Sent Items) results in a change to theitemId
field.