none
Event when adding a colleague

    Question

  • 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

    Friday, July 12, 2013 2:55 PM

Answers

  • 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

    Tuesday, July 16, 2013 7:50 AM

All replies

  • 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?

    Amit

    Friday, July 12, 2013 8:24 PM
  • 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

    Sunday, July 14, 2013 9:15 AM
  • 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 


    Mark ANSWER if this reply resolves your query, If helpful then VOTE HELPFUL
    Everything about SQL Server | Experience inside SQL Server -Mohammad Nizamuddin

    Tuesday, July 16, 2013 3:39 AM
  • 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

    Tuesday, July 16, 2013 7:50 AM
  • Hi

    how to add the Add colleague button in a list of user

    i.e. Sharepoint Page Reply section we going to show the user name and need to show Add Colleague option if user already exit need to call Remove college option

    Step of implement pls (using ascx / aspx custom page)


    sathish


    • Edited by cmsathish Tuesday, December 03, 2013 6:31 PM
    Tuesday, December 03, 2013 6:30 PM