Sitecore Bucket Structure – Item Field Value Based

Bucketing structure in Sitecore is a rule based where the default structure is derived from this setting

In this blog post I am going to share how we can create a bucket structure based on a field value of the item being created into a bucket as in consider News Articles or Products which has a field “Release Date” / “Posted Date”. It is good to create bucket structure based on these dates as compared to the created date of the item. Why? Content Authors can easily navigate through the bucket as they will have in hand information about when a new articles or product was released rather than remembering the created date of the Sitecore item.

So let’s buckle up seat belt and get hands on to see who we can achieve it,

Create a RuleAction class NewsReleaseDate that inherits from Sitecore.Buckets.Rules.Bucketing.RuleAction

public class NewsReleaseDateBasedPath : RuleAction

where T : BucketingRuleContext


#region ...Properties

public string Format { get; set; }


#region ...Public Methods

public const string CST = "Central Standard Time";

public override void Apply(T ruleContext)


string format = this.Format;

if (string.IsNullOrEmpty(format))


//Take the format for creating bucket structure from a custom setting defined in a configuratoin file

format = Sitecore.Configuration.Settings.GetSetting("BucketConfiguration.NewsReleaseDatePathFormat", "yyyy/MM/dd");


DateTime releaseDate = ConvertToCst(DateTime.UtcNow);

//master database is referenced as command runs under Core DB context

var item = Sitecore.Data.Database.GetDatabase("master").GetItem(ruleContext.NewItemId);

//if item is null bucket structure will be creadetd in default format

//So pass the yyyy/MM/dd format

if (item == null)


ruleContext.ResolvedPath = releaseDate.ToString(format, Context.Culture);



//AutoGenerated Model class for new article base

NewsArticleBaseItem newsItem = new NewsArticleBaseItem(item);

if (newsItem == null) return;

//Read the release date field value

if (newsItem.ReleaseDate!=null && !String.IsNullOrEmpty(newsItem.ReleaseDate.ToString()))


releaseDate = ConvertToCst(newsItem.ReleaseDate.DateTime.ToUniversalTime());


ruleContext.ResolvedPath = releaseDate.ToString(format, Context.Culture);


public DateTime ConvertToCst(DateTime utcDate)


return TimeZoneInfo.ConvertTimeFromUtc(utcDate, TimeZoneInfo.FindSystemTimeZoneById(CST));




Now make few tweaks to Sitecore,
1) Create Element Folder at path /sitecore/system/Settings/Rules/Definitions/Elements/


2) Create a new action and update the type field to refer to the code class created earlier.


3) On Item Buckets Setting at path /sitecore/system/Settings/Buckets/Item Buckets Settings
Add the rule and action for your template


Click on the Edit Rule to add new rule and action for News Release Date


You will see Bucketing News Elements folder now available


Save the Item bucket settings item and we are all set to create a news article which will get stored initially with the created date as you have still not changed the valued of the release date of the new news article. Once the release date field is updated the news article will move to the bucket structure based on the value provided in the release date field.

That’s all for now I have to share keep Sitecoring and keep sharing because “Sharing is Caring”

Leave a Reply

Your email address will not be published. Required fields are marked *