If you haven't already read my blog post on WorxBox, please take a moment and do so. One of the really nice features of WorxBox is item filtering. Item filtering uses Sitecore's rules engine and subsequently the rule set editor to allow content authors to quickly and easily see only the items they want to see. For authors who have worked with Personalization the activity will be very intuitive.

Adding New Conditions

WorxBox ships with 2 conditions, Items Changed by Me and Items Created by Me. These conditions are shortcuts to using one of the conditions found in Items category where one may enter a field, a value and an operator. The challenge with using the default condition is authors must know both how the internal fields are named (__Updated By and __Created By respectively) and must know how your particular security configuration names users. If one were to filter for the admin account, the value would need to be entered as sitecore\admin.

Adding new conditions is really simple and today we're going to look at how we can help our marketers launch a campaign by submitting items in the content tree associated with campaign and only those items. First, we're going to need a new condition! And since we're going to need to filter items in the workbox based on their association with a campaign, we'll need a condition that can read the Tracking field in content items.

The basic steps for adding any condition are as follows:

  1. Create a class that inherits from the appropriate condition type (we'll use WhenCondition for today's post).
  2. In your master database, navigate to /sitecore/system/Settings/Rules/Definitions/Elements/[Element Group]
  3. Add a new condition
  4. Set its Type
  5. Set its language text

Adding a Campaign Filter Condition

As mentioned, in order to determine if an item is associated with a campaign, we'll need to read its tracking field. The tracking field internally stores XML.

We have a couple options in terms of how we read the field contents. The first could be to use XDocument and parsing to find the campaign id. The second and perhaps cleaner approach is to use a special class provided for us in the Sitecore.Analytics assembly. First, let's create our condition.

public class ItemIsPartOfCampaign : WhenCondition where T : RuleContext
 public string CampaignItemId { get; set; }

 protected override bool Execute(T ruleContext)
 var trackingField = new Sitecore.Analytics.Data.TrackingField(ruleContext.Item.Fields["__tracking"]);
 return trackingField.CampaignIds.Contains(CampaignItemId);
} }

For this particular condition, we will need our content author to tell us what campaign they are interested in. To do this, we need to add a public string property that will store the campaign id passed in. Second, we'll use the TrackingField class to do the parsing work for us. This is a much cleaner approach than reading the raw XML given there are no guarantees Sitecore won't change the xml structure in the future. Last, we need to define our condition in the content tree and provide our authors with the ability to select a campaign from a list. We could force them to just type in the campaign id but we want to treat our content authors as well as we treat our consumers! When we define the condition within Sitecore, we need to add it to the appropriate conditions group and then specify the Type and the Text.

For our purposes, let's add our condition to the WorxBox conditions group. This is located at /sitecore/system/Settings/Rules/Definitions/Elements/WorxBox.

Item is Part of Campaign Condition

The content item name is the name of the condition the author will see. I advise that you make it a friendly name complete with spaces so that it's easily readable. The text field contains the condition language the author will see. Normally for when conditions, we'll use either "where" or "when" as this can be negated by the user . When negated, Sitecore injects "except" in the front of the condition text. The text in [] is interpreted by Sitecore so must be entered the correct way. The first item is the name of the public string property that will accept the campaign id. The second item indicates to Sitecore to show a treeview of items. The third indicates the starting path or root in the content tree. The last item indicates what to show when the campaign id hasn't been selected.

Once this rule has been incorporated the author can then interact with it when setting the filter to filter only those items that belong to the given campaign.

Rule Set Editor - Campaign Condition Selected


If you haven't installed the WorxBox module yet, I encourage you to download it and do so. You will make your content author's job much easier when it comes time for them to move content through workflow and wow your users! You can download WorxBox here. While we intend to provide support for earlier versions of Sitecore, WorxBox is currently only compatible with Sitecore 8.0, Sitecore 8.1 and 8.2. WorxBox Module 8.1 is the correct module package for both Sitecore 8.1 and Sitecore 8.2.