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
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
:
UpdateStatistics
- boolean indicating whether item statistics will be updated (i.e date and user). This is the most important setting for you.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)