I have several newly added save events for existing items. Any way to force a save of an item? When I do $item.Editing.BeginEdit() / $item.Editing.EndEdit() in PowerShell it returns false since nothing changed.

Trying to think of a field I can update to trick into thinking it changed.

  • Whats the reason that you want to trigger save events even if the item fields didnt change? – Ahmed Okour Aug 30 at 20:46
  • The item save events are updating fields from other items. Like item A needs a calculation from items B and C. So I need Item A to run a save to trigger the event to do the calculations. Its easier than trying to rebuild the calculation code in PowerShell. – Chris Auer Aug 30 at 21:08
up vote 2 down vote accepted

This is going to be a very short answer.

But $item.Editing.EndEdit($true, $false) should do the trick.

The two parameters are

  • updateStatistics
  • silent

Setting updateStatistics to true SHOULD force Sitecore to write a new Modified Date, Modified By etc. and thus force a save of your item.

Setting silent to true would defeat your purpose, as it would supress events.

Edited to add

But also be aware of this. I'm not sure if there's an issue involving Sitecore Powershell Extensions or what's going on.

Item.Editing.EndEdit() is not triggering save event when called from Powershell extension

I don't know if the following code can be run from Powershell extensions, But i remember the following Sitecore API used to raise the Item:Saved events :

Sitecore.Events.Event.RaiseItemSaved(this, new Sitecore.Data.Events.ItemSavedEventArgs(item));

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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