4

I've created a processor that archives items that haven't been updated in 2 years, and I'm trying to test this by altering a date of an item, but every time I change it and save, it reverts back. I'm signed in as an admin user. Is there a way to do this outside of manipulating the sql data?

1 Answer 1

6

The Updated Date statistic is automatically updated every time an item is changed. The only way to force the date not to be updated is programatically:

item.Editing.BeginEdit();
item[Sitecore.FieldIDs.Updated] = Sitecore.DateUtil.ToIsoDate(DateTime.MinValue);
item.Editing.EndEdit(false, false);

The important part is the 2 parameters passed to EndEdit:

  1. UpdateStatistics - boolean indicating whether item statistics will be updated (i.e date and user). This is the most important setting for you.

  2. Silent - boolean indicating whether events will be raised as a result of the item save, e.g. item:saved. If this interferes with your processor then you may also want to set this as false.

You can, of course, do the same in PowerShell Extensions:

$item.Editing.BeginEdit()
$item["__Updated"] = "20190829T231200Z"
$item.Editing.EndEdit($false, $false)
1
  • +1 for adding the PSE version, too! Sep 3, 2019 at 13:01

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.