A very useful feature in Sitecore is the ability to reset fields on an item to their value as defined in Standard Values. This is great, but what if you want to reset fields on many items of the same template?
There doesn’t (yet) appear to be a feature in Sitecore to do this, so I wrote a simple function that performs this task.
Basically, you will need to perform a search to get all your items first, then pass in your list of items and a list of the field names you wish to reset on each item.
public void ResetFields(List<Item> items, List<string> fields) { if (items.Any() && fields.Any()) { foreach (Item item in items) { ResetFieldsOnItem(item, fields); } } } public void ResetFieldsOnItem(Item item, List<string> fields) { if (item != null && fields.Any()) { using (new Sitecore.Security.Accounts.UserSwitcher(ELEVATED_USER_ACCOUNT, true)) { item.Editing.BeginEdit(); foreach (string field in fields) { item.Fields[field].Reset(); } item.Editing.EndEdit(); } } }
I might create a SPEAK app so that when you click on a template, a button will appear to provide this functionality in the Ribbon – That would be a nice addition 🙂
Hey, that’s pretty cool. Thanks for sharing. If you happen to be using the Sitecore PowerShell Extensions module found here http://goo.gl/G2ULkI you can try something like this. The following example will reset the Text field on the home item:
PS master:\> Get-Item master:\content\home | Clear-ItemProperty -Name Text
Cheers Michael:) That’s a great alternative for power users (permissions permitting)
I haven’t done a great deal with Sitecore Powershell yet, will have to take a closer look at that 🙂
We have tons of links to blogs and videos here to help you get started: http://blog.najmanowicz.com/sitecore-powershell-console/