Answered Post-processing of newly created contact

  • Friday, June 08, 2012 4:13 PM
     
     

    Hi,

    I'd like to do some post-processing of an Outlook.ContactItem after I've created it and the Contact editor has been closed.  I would like to be able to trap:

    1. User closes the contact editor (i.e. doesn't save it)
    2. User clicks 'Save and Close' for a new contact
    3. User clicks 'Save and Close' for a contact and Outlook finds one or more duplicates, and then two things can happen:
      1. User can choose to create a new contact
      2. User can update an existing contact - and there are two cases here:
        1. there were changes to merge in to the existing contact
        2. there were no changes to merge in to the existing contact

    In 3.2 (duplicate found, 'update' picked), the updated contact is no longer the original contact I created and have a reference to.

    I'm wondering if there are events I can trap or if there is anything in the Outlook.ContactItem I have a reference to that would tell me anything about its final disposition:

    • saved as itself
    • merged into another contact and that other contact was saved and if so, is a reference or ID for that other contact available anywhere
    • not saved at all

    Ideally, would like this for 2003, 2007 and 2010 in C#.

    Thanks,

    DAC


    • Edited by DAC_NW Friday, June 08, 2012 4:47 PM Better title
    •  

All Replies

  • Tuesday, June 12, 2012 8:43 AM
    Moderator
     
     

    Hi DAC,

    Thank you for posting to MSDN Forum.

    In accordance with your issue , I would suggest you some threads you were wondering respectively.

    • saved as itself—it's suggested  that you  can use the ContactItem.BeforeAutoSave event,which occurs before the item is automatically saved by Outlook.
    • merged into anther duplicate contact—I think you will delete the duplicate contact and save the other one , so the ContactItem.BeforeDelete event can be used.
    • not saved at all—as far as I know, there is no event to be used. However, you can try the ContactItem.Saved property.If you modify the contact after create it , the Saved property will have been False until the contact is saved.

    If I misunderstand you, please feel free to let me know so that I can improve my answers .

    Regards,

    Leo


    Leo_Gao [MSFT]
    MSDN Community Support | Feedback to us

  • Tuesday, June 12, 2012 3:38 PM
     
     

    Hi Leo,

    Thanks for the suggestions.  Unfortunately, the events don't get fired in all scenarios:

    • Not sure when BeforeAutoSave gets fired, but I couldn't get it to do so in my testing ('Save and Close' button, ctrl-S, etc.).  I can use the 'Write' event to trap this, as long as the contact is saved as a new contact (vs being merged into an existing contact).
    • BeforeDelete doesn't get fired.  My new contact has not yet been saved, so this probably doesn't get fired.  If I save it before displaying it, then Outlook's duplicate detection dialog doesn't get invoked.
    • Saved property will tell me if the contact I started with has been saved (i.e. saved as a new contact) - but it doesn't tell me if the contact was merged into another contact, and the merged contact saved.

    Thanks,

    DAC

  • Wednesday, June 13, 2012 3:52 PM
    Moderator
     
     Answered

    Hi DAC,

    Unfortunately the object model does not have anything in it to "directly" support the duplicate contact detection scenario in the UI. About all you can do is to take a more "distant" approach event-wise. Implement something like the FolderChange event and when that fires, look up the contact(s) based on key properties like FirstName, LastName, etc. And then based on what you find, you can likely determine what happened in terms of user selection. For example, if the EntryIDs are not the same, you can deduce that duplicate detection happened and the user chose to merge the contacts.

    The other option (if this is an in-house solution) would be to disable the built-in duplicate contact detection altogether. Theoretically, and optionally, your add-in could provide this functionality itself (and thus have full control over things). But of course that's a lot of work to implement.

    I'm sorry there isn't a better answer here, at least that I'm aware of.


    Bill Jacob - Microsoft Customer Service & Support - Developer Messaging

    • Marked As Answer by DAC_NW Wednesday, June 13, 2012 4:10 PM
    •  
  • Wednesday, June 13, 2012 4:10 PM
     
     

    Hi Bill,

    Thanks for the suggestions.  I've implemented some event handlers to trap everything I can think of when a 'save' is done ('Save and Close', 'File - Save', 'File - Save and New', CTRL-S, etc.) so I can tell when the item is saved.  I can then check the EntityID of my original contact - if the item was saved and the EntityID is not set, then I know the user merged the data into an existing contact.

    The only bit missing is how to get the ID of that merge contact - I'll try your suggestion of searching.

    I'm not keen on implementing my own duplicate detection...

    Thanks,

    Doug.