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 .

1 Answer 1

5

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 EventDisabler())
        {
            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>
4
  • where this method is called ? do i have to use pipelines to call this method ? Jul 3, 2019 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. Jul 3, 2019 at 10:28
  • ok thanks , will try this for sure , appreciate your help Jul 3, 2019 at 10:48
  • ItemSavedEventArgs didn't work for me. EventArgs worked, however. Here's an example of what worked for me: naveed-ahmad.com/2011/11/02/… Dec 30, 2019 at 19:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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