3

Do someone know if it's possible to attach an event receiver to profile updates?

The goal would be to update an external system (such as a CRM) when a user is updating his profile.

2 Answers 2

3

As James said, you could create a timer job to sync profile changes with the external system. But, to detect the changes in user profile properties, I would suggest you to look into UserProfileChangeCollection because it contains a complete log of changed user profiles.

using (SPSite site = new SPSite("http://server1"))
           {
               SPServiceContext serviceContext = SPServiceContext.GetContext(site.WebApplication.ServiceApplicationProxyGroup, SPSiteSubscriptionIdentifier.Default);
               UserProfileManager profileConfigManager = new UserProfileManager(serviceContext);
               try
               {
                   UserProfileChangeCollection collection = profileConfigManager.GetChanges(query);
                   foreach (UserProfileChange change in collection)
                   {
                       Console.WriteLine(change.AccountName);                               
                       if (change is UserProfileSingleValueChange)
                       {
                           UserProfileSingleValueChange propertyChange = (UserProfileSingleValueChange)change;
                           Console.WriteLine(propertyChange.ProfileProperty.Name);
                       }
                   }
               }
               catch (UserNotFoundException)
               {
               }

Read more on MSDN and Example

3

Not really - the User Profile properties aren't stored in a list (which is where Event Receivers are registered) - they're all stored in the User Profile Database which is managed by the User Profile Service Application.

If you want to sync profile changes with an external system, you can write a Timer Job to look up the user profile properties and synchronise them with your external system. You would configure the timer job to run at an interval, and maybe use the User Profile Change Log to find out what's been changed.

2
  • +1 for timer job sync with external system. Commented Jul 14, 2012 at 11:49
  • @James Love: Thanks for your answer. I credited Falak Mahmood because he was providing more details. However, if I could have split the points, I would have.
    – E. Jaep
    Commented Jul 14, 2012 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.