InspectorActivate is called after ProcessAttachmentAdd

Add-in Express™ Support Service
That's what is more important than anything else

InspectorActivate is called after ProcessAttachmentAdd
 
Sagi


Guest


Following https://www.add-in-express.com/creating-addins-blog/2011/09/06/outlook-item-events/ we connect to the mailItem on InspectorActivate and listen to Attcahment actions.
However, we've found that when there are multiple inspectors, this logic doesn't work.
The reason is, we connect to the first mail item (call it A) on InspectorActivate, then another inspector is created, call it B and we connect to it (disconnecting the first)
Now, drag and drop an attachment to MailItem A, InspectorActivate is called but ProcessAttachmentAdd won't be called. After debugging, we have discovered the InspectorActivate is called after ProcessAttachmentAdd is called.
Since ProcessAttachmentAdd is not an "official" Office event, I don't think it's an office issue bug an ADX issue?
Posted 10 Oct, 2020 07:34:48 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Hello Sagi,

Add-in Express events are issued as a reaction to Office events. Add-in Express manages internal wrappers for Explorer and Inspector objects and translates their events to the events of the ADXOutlookAppEvents. That is, no Add-in Express Outlook-related event is generated at a wish; all of them are generated following the corresponding event of the Outlook object model.

Since you've found that InspectorActivate (=Inspector.Activate) occurs after ProcessAttachmentAdd (={an Outlook item type such as MailItem, TaskItem, etc.}.AttachmentAdd), I suggest that you change the way you connect to events. Instead of managing a single Item Events object, you can have many events class instances: create a class instance once an item is loaded; see the OutlookApp.ItemLoad event. Get rid of an events class instance once the corresponding item is unloaded; see the {item type}.Unload event.

I can't tell why they fire events in that order. This case as well as other cases aren't officially explained. Or, maybe, we haven't found such explanations yet.

Here's what they officially suggest (from https://docs.microsoft.com/en-us/office/vba/outlook/concepts/electronic-business-cards/working-with-outlook-events):

Except for certain form events, your program cannot assume that events will occur in a particular order, even if they appear to be called in a consistent sequence. The order in which Outlook calls event handlers might change depending on other events that might occur, or the order might change in future versions of Outlook.



Andrei Smolin
Add-in Express Team Leader
Posted 12 Oct, 2020 02:44:01 Top
Sagi


Guest


Thank you Andrei.
Assuming we do want to have multiple Item Event instances, can you suggest how should we manage them?
I'd assume we need a unique ID for each item which exists on Application.ItemLoad event so we can retrieve the corresponding Item Event (for example for Unload).
Any thoughts on this Unique ID or any ability to save our Item Event aside and trace it back to a MailItem?
Posted 12 Oct, 2020 04:27:31 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Hello Sagi,

For an existing (=saved) email you would use MailItem.EntryId. As to newly created unsaved emails, you can create a UserProperty on the email item and use it to identify the email. Two points: 1) you should create a UserProperty in the first InspectorActivate for that item, 2) you should delete the UserProperty before you send that email (say, you can delete that user property once the email is saved (autosaved) or in the ItemSend event.


Andrei Smolin
Add-in Express Team Leader
Posted 12 Oct, 2020 04:43:29 Top
Sagi


Guest


Thank you Andrei.
That's indeed similar to what we've implemented. I've tried your first suggestion but it looks like it isn't possible to access the item properties within an event (ItemLoad) so we can't check if it's "Sent" or not.
If we'll connect to all mails we'll probably experience performance penalty.
Any idea how to work around that?
Posted 12 Oct, 2020 05:03:16 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Hello Sagi,

Sagi writes:
I've tried your first suggestion but it looks like it isn't possible to access the item properties within an event (ItemLoad) so we can't check if it's "Sent" or not.


That's why I suggest using the first InspectorActivate. Or, you can use the {the item}.Open event.

Sagi writes:
If we'll connect to all mails we'll probably experience performance penalty.


Assuming that you talk about finding an events class instance to react to an event of an item, I don't see a way to bypass the loop. Also, I assume, this loop will be run in the code of Outlook, not in the code of your add-in.


Andrei Smolin
Add-in Express Team Leader
Posted 12 Oct, 2020 08:17:47 Top