2

How do I update the item creation date programmatically for migrated content? As the content items are created programmatically, the created date is always the current date when the script is being executed.

I would like to modify the date of item creation so that my item bucketing rules are executed accordingly.

4

Just set it:

var itemToHack = Sitecore.Context.Database.GetItem("/sitecore/content/YouPath");
using (new Sitecore.SecurityModel.SecurityDisabler())
{
    itemToHack.Editing.BeginEdit();
    itemToHack[Sitecore.FieldIDs.Created] = Sitecore.DateUtil.ToIsoDate(DateTime.MinValue);
    itemToHack.Editing.EndEdit();
}

Source: https://gist.github.com/ncelico/25b939b4fe7d647e6431

  • I want the item created date (read only) created by item:created event handler to be updated in my database so that item bucketing rules are running against that date. This logic will update the created date in the statistics section and when new version is created, then item will move to different bucket as item creation date will be new. – sindhu Mar 25 '19 at 23:14
  • 3
    Then set your system time before creation lol. You're working the wrong problem here. In the code you use for migration, set the created date to what you want. – Mark Cassidy Mar 25 '19 at 23:18
  • @MarkCassidy I think the EndEdit() should have the value false for the UpdateStatistic parameter as on Save, it will re-update the date. EndEdit(false, false) – Hishaam Namooya Apr 25 '19 at 7:06
  • Not the created date. Updated, yes. – Mark Cassidy Apr 25 '19 at 7:22

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.