Event when adding a colleague

Hi,

I'd like to execute some code when adding (and removing) colleagues.

I cannot change the "Add colleague" form.

The issue is that I need to sync the colleagues with a third party tool that has some custom memberships.

The other option is to have a timerjob looking for new/deleted colleagues, but I'd like to avoid that.

Thanks & Cheers

July 12th, 2013 10:59am

Is this a SharePoint list that you are adding your colleagues to? If that is the case did you look at Event Receiver or workflow option? If this does not answer your question can you please elaborate your question?
Free Windows Admin Tool Kit Click here and download it now
July 12th, 2013 4:27pm

Hello,

It's the Sharepoint Out Of The Box Colleagues, available on the "my Site".

I can manage the colleagues programatically using the colleague manager (http://msdn.microsoft.com/en-us/library/Microsoft.Office.Server.UserProfiles.ColleagueManager.aspx).

The only thing I need and I can't find is how to attach an event when someone uses the OOTB form to add or remove colleagues.

Thanks & Cheers

July 14th, 2013 5:16am

I hope you are using SharePoint list, When you add colleagues, you can write event handler on the list for Item adding or Item added event and write whatever code you want. similarly you can write event handler for delete 
Free Windows Admin Tool Kit Click here and download it now
July 15th, 2013 11:41pm

Sorry, but no, I'm not using a list.

As I said previously, I'm using the SP OOTB Colleagues functionality (http://office.microsoft.com/en-001/sharepoint-server-help/add-new-colleagues-and-manage-your-colleague-list-HA101665476.aspx).

For the time being I have found a workaround. I need to synchronize the Colleagues with a third party membership, so for now I have a Timer Job looking into the profile changes using a UserProfileChangeQuery and getting all the profile changements for all users since the last execution of the TimerJob.

I leave you with the piece of code that manages that, in case someone needs to do the same.

//profile refers to the current user UserProfile
//change query is the UserProfileChangeQuery object



UserProfileChangeCollection changes = profile.GetChanges(changeQuery);

foreach (UserProfileChange change in changes)
{

	if (change.ObjectType == ObjectTypes.Colleague)
	{
		var colleageChange = (UserProfileColleagueChange)change;

		SPUser user = web.SiteUsers[colleageChange.Colleague["AccountName"].ToString()];

		switch (colleageChange.ChangeType)
		{
			case ChangeTypes.Add:
			
				//user added a colleague
				
				break;
			case ChangeTypes.Delete:
			
			   	//user removed a colleague 
				
			   break; 
			default:
				break;
		}
	}
}

Cheers

July 16th, 2013 3:52am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics