Wednesday, September 30, 2015

Managing the Sitecore xDB Contact Card without requiring the Tracker Revisited

Intro

Previously I mentioned how to update the contact card without the session.  I found that I was occasionally still getting locking issues, so I looked into it a bit further.  What I had was a little redundant for saving the update.

Saving Updates

When saving the updates really you do not need to call SaveAndReleaseContact, FlushContactToXdb should do the trick, but you should call it with the overload that takes two parameters and passin a new ContactSaveOptions with release set to true, and a new LeaseOwner.
var manager = Factory.CreateObject("tracking/contactManager"trueas ContactManager;
 
manager.FlushContactToXdb(contact, new ContactSaveOptions(true, new LeaseOwner(AnalyticsSettings.ClusterName, LeaseOwnerType.WebCluster)));
manager.SaveAndReleaseContact(contact);
 

Conclusion

While this is only a short note on the last post, be sure to wrap your contact manager to ensure you maintain the same contact card between your updates and when you flush the card or your changes will be lost, and only identify the contact when absolutely necessary to prevent a chance for potential conflict with locking.