0

I was bucketing an item in Sitecore, and did some customizations it the folder structure also, I followed this link custom buckets, and the bucket structure which is being created is based on the date field, but the issue is, what if I want to automate the sync of the bucket folder on the date field without manually going to Sitecore and sync the bucket item .

4

There are multiple options for this based on your requirement. if you want to simply do it in the Sitecore you can use Item save event but if you want it in outside the sitecore client then you need to write your custom code to run

BucketManager.Sync(bucketItem);

sample code for item:saved event

public class ItemSavedEventHandler
{
    public void Execute(object sender, ItemSavedEventArgs args)
    {
        Assert.IsNotNull(sender, "sender is null");
        Assert.IsNotNull(args, "args is null");
    using (new EventsDisabler())
    {
        var parameter = args.Item;
        if (!BucketManager.IsItemContainedWithinBucket(paremeter))
        {
            return;
        }

        var bucketItem = parameter.GetParentBucketItemOrParent();
        if (!bucketItem.IsABucket())
        {
            return;
        }

        BucketManager.Sync(bucketItem);
    }
  }
}

You need to create a custom configuration -

<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <events>
      <event name="item:saved">
        <handler type="XYZ.Events.ItemSavedHandler, XYZ" method="OnItemSaved">
        </handler>
      </event>
    </events>
  </sitecore>
</configuration>
  • where this method is called ? do i have to use pipelines to call this method ? – Rohan Bhateja Jul 3 at 10:06
  • you need to add a custom configuration for calling your handler on "item:saved" event. I have updated the answer for this. – Mahendra Shekhawat Jul 3 at 10:28
  • ok thanks , will try this for sure , appreciate your help – Rohan Bhateja Jul 3 at 10:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.