Tag Sitecore content with Profile Card Programmatically

During the last few days, I was working on a module where I had to tag different Sitecore items with a profile card programmatically. At first, I thought it was an easy task but it came out it wasn’t.

So, during this post, I will explain the different steps on how to tag an item with a Profile card programmatically. First, let us see the different Profiles with their profile cards:

I have created a Profile named Editorial with profile keys Article, Blog, Image and Video. Moreover, I have created the Profile Cards with the same name as the profile keys. Below is a screenshot of the representation of the Profile, Profile Keys and Profile Cards.

Capture.PNG

Flow to retrieve and set the item profile cards

Untitled Diagram.png

Code Implementation

We need to first retrieve the tracking information from the item we want to tag. We can do so by

Let’s implement the TagProfile method. The TagProfile method will retrieve the different presets (Profile Cards) and then update the tracking field accordingly with the Profile Keys

The below method will retrieve the list of Profile Cards based on a list of Sitecore item ids I have provided.

Note that I have a class named PresetInfo to store the details of the Profile Cards.

The final steps within the TagProfile method is to set the different profile keys.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s