I have a very basic Outlook add-in which takes information from the user's computer and attaches it to an email, as a part of a help desk ticketing system. To avoid any hassle with file uploads, I want to use the Office.context.mailbox.item.addFileAttachmentFromBase64Async()
method for attaching the information. The problem is this:
The add-in is intended to be clicked from the ribbon while the user is in read mode, and it calls the displayNewMessageFormAsync()
method, thus opening the message form with certain information prefilled. When I subsequently call Office.context.mailbox.item.addFileAttachmentFromBase64Async()
, however, the item referred to is still the item that the user was reading - not the new item that is being composed.
I have trawled through the MS Docs for the JS API, and I can't see any way to change the selection of the item programatically. Is there a way to do that, or an alternate way to get my file attached? The important thing in my mind is keeping the user's steps down to one (just click the button while in read mode); if they have to start composing a message themselves and then click it, I think they just won't click it.
If your goal is to attach an Attachment to the new message created by displayNewMessageFormAsync() the only way to do that is with the Attachment parameter. However, that parameter only allows you to upload a file that you have the URL to. (NOT a Base64 Encoded Attachment).
If you are requesting new functionality to displayNewMessageFormAsync to support Base64 Attachment, that would need to be a new feature request made at: https://techcommunity.microsoft.com/t5/microsoft-365-developer-platform/idb-p/Microsoft365DeveloperPlatform
Currently the "scope" of each instance of an add-in is Item Level. (i.e. an Add-in really only has direct access to the Item that it is opened on. There are some exceptions to this. (such as Rest/EWS calls and pinned add-ins) But nothing that would be a workaround to your scenario.
You could have an add-in in the Compose Scenario that the user could open once the new message is created, but that probably isn't what you are looking for.