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.
Flow to retrieve and set the item profile cards
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.