BCM 2007 events

  • Thread starter Thread starter Aidal
  • Start date Start date
A

Aidal

Hi NG.

I'm trying to write an application or add-in that has to act on some
events from BCM for Outlook 2007.

The events i'm interested in are events like Created, Updated and
Deleted on entities/objects like Accounts, Contacts etc. (most of which
are ContactItem objects).

I have been able to find "some" events on the ContactItem object but far
from enough to satisfy my needs.

I would very much like to know:
-------------------------------
1) Where do I find these events (what objects should I be looking at if
not ContactItem) ?

2) How do I go about writing and adding these eventhandlers (I've seen
an example in VBA but not for the objects I'm interested in and
everything I've tried with any existing event on the objects of my
interest have not been successful) ?
-------------------------------
I write in C# myself. If anyone can answer any of these questions and
maybe even supply code examples or links to some "useful" examples it
would be very much appreciated, thanks :)

/Aidal
 
You might want to start the documentation at http://msdn2.microsoft.com/en-us/library/aa431857.aspx. For events, you'll be using those exposed by the Outlook object model, so you might also find http://msdn.microsoft.com/vcsharp/default.aspx?pull=/library/en-us/dv_vstechart/html/ol03csharp.asp and http://www.outlookcode.com/codedetail.aspx?id=797 useful.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Sue Mosher [MVP-Outlook] skrev:
You might want to start the documentation at http://msdn2.microsoft.com/en-us/library/aa431857.aspx. For events, you'll be using those exposed by the Outlook object model, so you might also find http://msdn.microsoft.com/vcsharp/default.aspx?pull=/library/en-us/dv_vstechart/html/ol03csharp.asp and http://www.outlookcode.com/codedetail.aspx?id=797 useful.

Ok, I've checked out the links and I also build the test add-in from one
of the links... So I did learn somthing and it was useful but still not
what I wanted.

I found from what I read and also tested a little that maybe Explorers
and Inspectors could be useful, but from what I saw, it's about the UI
areas and forms in Outlook not object events.

I did consider maybe one could access the "right" form and then find the
"right" button and then subscribe to it's Clicked event, using Explorers
or Inspectors, but if an object like an Account (which is infact an
Outlook.ContactItem) is accessible from other places than from the form
used for Accounts, then this method doesn't work, because the object
could be altered without ever openening the Account form hence making
the subscribtion to the Save- or SaveAndClose-button on the form
completely useless.

-------------------
So, if anyone could provide an example or a link to one that explains
how to:

1) Do somthing when ever a ContactItem (or Account) is created.
2) Do somthing when ever a ContactItem (or Account) is edited.
3) Do somthing when ever a ContactItem (or Account) is deleted.

I do realize that Created and Edited might infact just be "Saved" and
that would be ok as well.

Wether this be subscribing to pre-defined events (which I have been
unable to find), creating custom events or using whatever other means to
get a notification when these events (1, 2 and 3) occurres, doesn't
matter to me as long as it works and as long as it will always trigger
regardless of from where and by whom the object was altered.

/Aidal
 
1) Do somthing when ever a ContactItem (or Account) is created.

Subscribe to the MAPIFolder.Items.ItemAdd event for the desired folder(s). The sample at http://www.outlookcode.com/codedetail.aspx?id=456 is for the Sent Items folder, but it can supplement the information on that event in Help.
2) Do somthing when ever a ContactItem (or Account) is edited.

MAPIFolder.Items.ItemChange event. Another sample to supplement what's in Help: http://www.outlookcode.com/codedetail.aspx?id=566
3) Do somthing when ever a ContactItem (or Account) is deleted.

There's no surefire way to catch that until Outlook 2007. ContactItem.BeforeDelete fires only if the user has the item open and MAPIFolder.Items.ItemRemove doesn't return the item that was removed. One approach is to maintain your own list of what items are in each folder and check it against the actual folder contents whenever ItemRemove fires.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


Aidal said:
Sue Mosher [MVP-Outlook] skrev:
You might want to start the documentation at http://msdn2.microsoft.com/en-us/library/aa431857.aspx. For events, you'll be using those exposed by the Outlook object model, so you might also find http://msdn.microsoft.com/vcsharp/default.aspx?pull=/library/en-us/dv_vstechart/html/ol03csharp.asp and http://www.outlookcode.com/codedetail.aspx?id=797 useful.

Ok, I've checked out the links and I also build the test add-in from one
of the links... So I did learn somthing and it was useful but still not
what I wanted.

I found from what I read and also tested a little that maybe Explorers
and Inspectors could be useful, but from what I saw, it's about the UI
areas and forms in Outlook not object events.

I did consider maybe one could access the "right" form and then find the
"right" button and then subscribe to it's Clicked event, using Explorers
or Inspectors, but if an object like an Account (which is infact an
Outlook.ContactItem) is accessible from other places than from the form
used for Accounts, then this method doesn't work, because the object
could be altered without ever openening the Account form hence making
the subscribtion to the Save- or SaveAndClose-button on the form
completely useless.

-------------------
So, if anyone could provide an example or a link to one that explains
how to:

1) Do somthing when ever a ContactItem (or Account) is created.
2) Do somthing when ever a ContactItem (or Account) is edited.
3) Do somthing when ever a ContactItem (or Account) is deleted.

I do realize that Created and Edited might infact just be "Saved" and
that would be ok as well.

Wether this be subscribing to pre-defined events (which I have been
unable to find), creating custom events or using whatever other means to
get a notification when these events (1, 2 and 3) occurres, doesn't
matter to me as long as it works and as long as it will always trigger
regardless of from where and by whom the object was altered.

/Aidal
 
Sue Mosher [MVP-Outlook] skrev:
Subscribe to the MAPIFolder.Items.ItemAdd event for the desired folder(s). The sample at http://www.outlookcode.com/codedetail.aspx?id=456 is for the Sent Items folder, but it can supplement the information on that event in Help.


MAPIFolder.Items.ItemChange event. Another sample to supplement what's in Help: http://www.outlookcode.com/codedetail.aspx?id=566


There's no surefire way to catch that until Outlook 2007. ContactItem.BeforeDelete fires only if the user has the item open and MAPIFolder.Items.ItemRemove doesn't return the item that was removed. One approach is to maintain your own list of what items are in each folder and check it against the actual folder contents whenever ItemRemove fires.
Thanks for your reply Sue.

I will try this out right away.

By the way, about the "deleted" event, it is infact Outlook + BCM 2007
I'm developing for.


/Aidal
 
Sorry, I missed that. For Outlook 2007, you can use the Folder.BeforeItemMove event.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Sue Mosher [MVP-Outlook] skrev:
Subscribe to the MAPIFolder.Items.ItemAdd event for the desired folder(s). The sample at http://www.outlookcode.com/codedetail.aspx?id=456 is for the Sent Items folder, but it can supplement the information on that event in Help.


MAPIFolder.Items.ItemChange event. Another sample to supplement what's in Help: http://www.outlookcode.com/codedetail.aspx?id=566


There's no surefire way to catch that until Outlook 2007. ContactItem.BeforeDelete fires only if the user has the item open and MAPIFolder.Items.ItemRemove doesn't return the item that was removed. One approach is to maintain your own list of what items are in each folder and check it against the actual folder contents whenever ItemRemove fires.

Ok, I've checked out your example. I'm not sure I've translated your
code correctly to C# though.

I've created my own little class to test and am trying to use it from a
console application.
-----------------------------------
// available within the class
Outlook.ApplicationClass olAppClass;
Outlook.NameSpace olNameSpace;
Outlook.Folders olFolders;
Outlook.MAPIFolder olBcmRootFolder;

// Within my class constructor
olAppClass = new Outlook.ApplicationClass();
olNameSpace = olAppClass.GetNamespace("MAPI");
olFolders = olNameSpace.Session.Folders;
olBcmRootFolder = olFolders["Business Contact Manager"];

olBcmRootFolder.Folders["Accounts"].Items.ItemAdd += new
Outlook.ItemsEvents_ItemAddEventHandler(InstanceAdded_Account);

// No longer within constructor
public void InstanceAdded_Account(object item)
{
Console.WriteLine("account created: " +
((Outlook.ContactItem)item).FullName);
}
-----------------------------------
This should give me some console output when an Account is created or am
I missing somthing here?

Does the delegate have to have a certain name in order for it to work maybe?

/Aidal
 
That's on the right track but needs some refinement. You must to declare an explicit Items object at the class level, instantiate it in your procedure, and then create the event handler. The Items object must be a class-level object in order to persist so that it can fire events.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


Aidal said:
Sue Mosher [MVP-Outlook] skrev:
Subscribe to the MAPIFolder.Items.ItemAdd event for the desired folder(s). The sample at http://www.outlookcode.com/codedetail.aspx?id=456 is for the Sent Items folder, but it can supplement the information on that event in Help.


MAPIFolder.Items.ItemChange event. Another sample to supplement what's in Help: http://www.outlookcode.com/codedetail.aspx?id=566


There's no surefire way to catch that until Outlook 2007. ContactItem.BeforeDelete fires only if the user has the item open and MAPIFolder.Items.ItemRemove doesn't return the item that was removed. One approach is to maintain your own list of what items are in each folder and check it against the actual folder contents whenever ItemRemove fires.

Ok, I've checked out your example. I'm not sure I've translated your
code correctly to C# though.

I've created my own little class to test and am trying to use it from a
console application.
-----------------------------------
// available within the class
Outlook.ApplicationClass olAppClass;
Outlook.NameSpace olNameSpace;
Outlook.Folders olFolders;
Outlook.MAPIFolder olBcmRootFolder;

// Within my class constructor
olAppClass = new Outlook.ApplicationClass();
olNameSpace = olAppClass.GetNamespace("MAPI");
olFolders = olNameSpace.Session.Folders;
olBcmRootFolder = olFolders["Business Contact Manager"];

olBcmRootFolder.Folders["Accounts"].Items.ItemAdd += new
Outlook.ItemsEvents_ItemAddEventHandler(InstanceAdded_Account);

// No longer within constructor
public void InstanceAdded_Account(object item)
{
Console.WriteLine("account created: " +
((Outlook.ContactItem)item).FullName);
}
-----------------------------------
This should give me some console output when an Account is created or am
I missing somthing here?

Does the delegate have to have a certain name in order for it to work maybe?

/Aidal
 
Sue Mosher [MVP-Outlook] skrev:
That's on the right track but needs some refinement. You must to declare an explicit Items object at the class level, instantiate it in your procedure, and then create the event handler. The Items object must be a class-level object in order to persist so that it can fire events.

Ok, now I have this. I've created an Outlook.Items object like you
described, and attatched the event handler to that object - but it still
doesn't have any effect.
I still get no message in my console when an Account is created :/

To me the syntax here makes sense so either I'm very close or I'm just
misunderstanding your descriptions.
-----------------------------------------------
// class variables
private Outlook.ApplicationClass appClass;
private Outlook.Application app;
private Outlook.NameSpace nameSpace;
private Outlook.Folders folders;
private Outlook.MAPIFolder bcmRootFolder;
private Outlook.Items olItems;

// in constructor
this.appClass = new Outlook.ApplicationClass();
this.app = (Outlook.Application)this.appClass;
this.nameSpace = this.appClass.GetNamespace("MAPI");
this.folders = this.nameSpace.Session.Folders;
this.bcmRootFolder = this.folders["Business Contact Manager"];

this.olItems = this.bcmRootFolder.Folders["Accounts"].Items;
this.olItems.ItemAdd += new
Outlook.ItemsEvents_ItemAddEventHandler(InstanceAdded_Account);

// outside constructor
public void InstanceAdded_Account(object item)
{
Console.WriteLine("ACCOUNT CREATED: " +
((Outlook.ContactItem)item).FullName);
}
 
Sorry, I don't write C# code, so I can't tell you why it's not working. From my limited ability to read C#, no problem jumps out at me.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


Aidal said:
Sue Mosher [MVP-Outlook] skrev:
That's on the right track but needs some refinement. You must to declare an explicit Items object at the class level, instantiate it in your procedure, and then create the event handler. The Items object must be a class-level object in order to persist so that it can fire events.

Ok, now I have this. I've created an Outlook.Items object like you
described, and attatched the event handler to that object - but it still
doesn't have any effect.
I still get no message in my console when an Account is created :/

To me the syntax here makes sense so either I'm very close or I'm just
misunderstanding your descriptions.
-----------------------------------------------
// class variables
private Outlook.ApplicationClass appClass;
private Outlook.Application app;
private Outlook.NameSpace nameSpace;
private Outlook.Folders folders;
private Outlook.MAPIFolder bcmRootFolder;
private Outlook.Items olItems;

// in constructor
this.appClass = new Outlook.ApplicationClass();
this.app = (Outlook.Application)this.appClass;
this.nameSpace = this.appClass.GetNamespace("MAPI");
this.folders = this.nameSpace.Session.Folders;
this.bcmRootFolder = this.folders["Business Contact Manager"];

this.olItems = this.bcmRootFolder.Folders["Accounts"].Items;
this.olItems.ItemAdd += new
Outlook.ItemsEvents_ItemAddEventHandler(InstanceAdded_Account);

// outside constructor
public void InstanceAdded_Account(object item)
{
Console.WriteLine("ACCOUNT CREATED: " +
((Outlook.ContactItem)item).FullName);
}
 
Sue Mosher [MVP-Outlook] skrev:
Sorry, I don't write C# code, so I can't tell you why it's not working. From my limited ability to read C#, no problem jumps out at me.

Just to test that my eventhandlers worked at all I tried to attatch to
one of the default folders of Outlook like you do.

------------------------
Outlook.Items olItems;

olItems =
(Items)this.olNameSpace.GetDefaultFolder(OlDefaultFolders.olFolderContacts).Items;

olItems.ItemAdd += new ItemsEvents_ItemAddEventHandler(olItems_ItemAdd);
------------------------
And this works just fine.

Unfortunately the BCM folders aren't default folders of Outlook, so I
cannot do what I want with GetDefaultFolder().

I've tried loads of other appreaches to attatching eventhandlers to the
BCM folders but with no luck so far.

If anyone has a working example, it would be much appreciated.

/Aidal
 
How you get the folder shouldn't affect how the event handler works, as long as the event-firing object (olItems) is declared at the class level.

Maybe it's a limitation of the BCM data store that it doesn't fire normal Items events. You could ask about that on the microsoft.public.outlook.bcm group.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


Aidal said:
Sue Mosher [MVP-Outlook] skrev:
Sorry, I don't write C# code, so I can't tell you why it's not working. From my limited ability to read C#, no problem jumps out at me.

Just to test that my eventhandlers worked at all I tried to attatch to
one of the default folders of Outlook like you do.

------------------------
Outlook.Items olItems;

olItems =
(Items)this.olNameSpace.GetDefaultFolder(OlDefaultFolders.olFolderContacts).Items;

olItems.ItemAdd += new ItemsEvents_ItemAddEventHandler(olItems_ItemAdd);
------------------------
And this works just fine.

Unfortunately the BCM folders aren't default folders of Outlook, so I
cannot do what I want with GetDefaultFolder().

I've tried loads of other appreaches to attatching eventhandlers to the
BCM folders but with no luck so far.

If anyone has a working example, it would be much appreciated.

/Aidal
 
Sue Mosher [MVP-Outlook] skrev:
How you get the folder shouldn't affect how the event handler works, as long as the event-firing object (olItems) is declared at the class level.

Maybe it's a limitation of the BCM data store that it doesn't fire normal Items events. You could ask about that on the microsoft.public.outlook.bcm group.

Just a thought brought to me by somone else...

Could CDO be used for somthing usefull on this matter?

I have not done anything with CDO yet, but if it could solve my problem
I'm willing to give it a shot.

Does anyone know?

/Aidal
 
CDO has no event handling, so it's not relevant.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers


Aidal said:
Sue Mosher [MVP-Outlook] skrev:
How you get the folder shouldn't affect how the event handler works, as long as the event-firing object (olItems) is declared at the class level.

Maybe it's a limitation of the BCM data store that it doesn't fire normal Items events. You could ask about that on the microsoft.public.outlook.bcm group.

Just a thought brought to me by somone else...

Could CDO be used for somthing usefull on this matter?

I have not done anything with CDO yet, but if it could solve my problem
I'm willing to give it a shot.

Does anyone know?

/Aidal
 
Sue Mosher [MVP-Outlook] skrev:
CDO has no event handling, so it's not relevant.

Ok, thanks for all your replies Sue, I appreciate it :)

I'm gonna wait and see what happens for a bit I think. I still very much
need to know how to listen to BCM events though, but it doesn't seem
like anyone have really cracked that one yet.

/Aidal
 
Back
Top