1

I have been running into a blocker while developing an O365 Add-in.

Windows Desktop O365 issue: When opening my Add-in for the first time in a compose setting I have access to the Office.context.mailbox.item, however all inline "Reply" and "Reply All"s have my cached Add-in. For this cached Add-in ItemChanged async events do not have access toOffice.context.mailbox.item unless we wait a moment. I.E. Office.context.mailbox.item is undefined.

So in summary the cached Add-in offers a complex issue. ItemChanged shows when a user changes between emails. However what can I do if I have no access to the item?

I thought I would also mention all pop-out "Reply" and "New message" work as anticipated, and all OWA works with the above logic.

Has anyone else faced this issue, or is there a work around of sorts to reestablish the mailbox item once the Add-in in a compose setting has cached?

Code running in my compose Add-in:

export class BaseModule {
       constructor() {}
       
    Office.context.mailbox.addHandlerAsync( Office.EventType.ItemChanged, 
    (eventType) => { console.log(Office.context.mailbox.item.itemId) } 

}
wsoccorsi
  • 45
  • 8
  • Could you share the Outlook build number you are using to test this/seeing this behavior on? Also could you please elaborate the steps to reproduce this issue and what behavior is it that you're seeing that seems broken. – Outlook Add-ins Team - MSFT Nov 07 '20 at 17:07
  • Sure @OutlookAdd-insTeam-MSFT, I went ahead and edited some of that description that seemed confusing. My build number is: Version 2012 (Build 13430.20000) To reproduce: 1. Compose a "Reply" (not as a pop out) 2. Request `Office.context.mailbox.item` (You will receive in the first call) 3. Click "Reply" on a different email 4. Request `Office.context.mailbox.item` (This will be null) – wsoccorsi Nov 09 '20 at 14:18
  • Can you please clarify your scenario a bit more. What do you mean by "cached add-in"? Are you pinning your add-in? – Outlook Add-ins Team - MSFT Nov 09 '20 at 22:41
  • Ah yes sorry, once you pin the Add-in it will cache unless the action pops out. – wsoccorsi Nov 10 '20 at 13:55
  • Just to clarify your reproduction, `Office.context.mailbox.item` is only null for a brief moment in your step 4? If so, then the described behavior is consistent with how Outlook Desktop in Windows behaves. `Office.context.mailbox.item` can be null when you're switching between items, deselected an item or selected an item header. Can you describe what actions you want to take that this issue is preventing you from doing? – Outlook Add-ins Team - MSFT Nov 10 '20 at 22:14
  • `Office.context.mailbox.item` can be null even when you have selected an item? I.E. I click an email, I register an `ItemChanged` event and my item can be `null`? As for your other question this is preventing me from grabbing a new emails HTML. I click an email, try and grab the body with `Office.context.mailbox.item.body` and get an error. (Again only from a pinned/cached sidebar). A work around to this is `window.location.reload()`, but I believe that defeats the purpose of pinning. – wsoccorsi Nov 10 '20 at 22:29
  • When you select an item, is `Office.context.mailbox.item` null for a brief moment or permanently? You stated above that it was null 'unless we wait a moment'. – Outlook Add-ins Team - MSFT Nov 11 '20 at 00:30
  • Yes that could use some more clarification. So `Office.context.mailbox.item` is `null` for a brief moment in OWA but permanently, unless the window is reloaded on Windows Desktop – wsoccorsi Nov 11 '20 at 15:09
  • Can you please share your code snippet that you are using to reproduce this issue? – Outlook Add-ins Team - MSFT Nov 11 '20 at 20:49
  • Sure, so to get a good baseline of this issue have this code in a pinned Add-in in Outlook Desktop and "reply" or "reply all" inline, not pop out. `Office.context.mailbox.addHandlerAsync( Office.EventType.ItemChanged (eventType) => { Office.context.item.itemId // This will error out in cached circumstances });` – wsoccorsi Nov 11 '20 at 21:19
  • Can you clarify if `Office.context.mailbox.item` is null or if `Office.context.mailbox.item.itemId` is null? For example, instead of `Office.context.mailbox.item.itemId` can you try `Office.context.mailbox.item.subject`?`Office.context.mailbox.item.itemId` is only available for read items and not compose items like reply and reply all, as documented [here](https://learn.microsoft.com/en-us/office/dev/add-ins/reference/objectmodel/requirement-set-1.5/office.context.mailbox.item). – Outlook Add-ins Team - MSFT Nov 11 '20 at 22:56
  • `Office.context.mailbox.item` is `null` sadly. So that call will error out because `item` is `undefined` and therefore a call for the `itemId` errors out. – wsoccorsi Nov 11 '20 at 23:08
  • When you implement event handlers, we recommend always checking if `Office.context.mailbox.item` is null before using it, as stated in the documentation [here](https://learn.microsoft.com/en-us/office/dev/add-ins/outlook/pinnable-taskpane#implement-the-event-handler). When switching items, `Office.context.mailbox.item` can be null for a brief moment before the handler receives the new item. – Outlook Add-ins Team - MSFT Nov 12 '20 at 00:08
  • @OutlookAdd-insTeam-MSFT wonderful I believe thats what I was missing! I've come up with a solution where I polling the `item`. Thanks for the patience I highly appreciate it. – wsoccorsi Nov 12 '20 at 20:52

1 Answers1

0
 let timer = setInterval(getOfficeItem, 1000);
 function getOfficeItem {
     if (Office.context.mailbox.item) {
        // Your logic
        clearInterval(timer);
     }
  }

Above is a block of code that I was able to come up with to await the Office item on an ItemChanged event

Update: This seems to have been fixed for replies but not drafts.

wsoccorsi
  • 45
  • 8