Reputation:
In Sitecore 7.2 I have a folder with many items that I need to convert into Buckets. I checked bucketable in Standard Values for that template (as per official documentation), so all new items are coming into bucket but I also need to update that field within almost hundred existing items. Any smart way of doing that?
Also, previously I came across similar case when I required to update disabled field for all existing items of certain template, so may be there is some universal solution?
Upvotes: 2
Views: 5334
Reputation: 8355
For your bucket scenario, if I understand you correctly, you just want to update a folder with existing items to be a bucket. It sounds like you have configured it correctly. You don't need to go to each existing item and update the Bucketable
setting. If you have set it in standard values you just need to Sync the bucket and Sitecore will take care of the rest.
In terms of bulk-editing items, either of @martin-miles' solutions will work. I would probably opt for the PowerShell approach but keep in mind that it's a sharp tool so it's worth testing your command or script on a smaller dataset before doing a full run. Another option to consider is the Revolver tool. This is an example of changing all descendants below the current directory:
find -r (sf bucketable 1)
Upvotes: 2
Reputation: 2096
From what I know there are 2 ways of doing that - straightforward with the code, and smart with PowerShell module (if you have one installed). Unfortunately, I do not think there is specific interface in Sitecore Desktop for doing that.
1.Doing mass update from the C# code:
private void UpdateAllFieldsRecursively(Item parentItem, string templateName, string fieldName, string newValue)
{
if (parentItem != null)
{
using (new SecurityDisabler())
{
foreach (Item childItem in parentItem.Children)
{
if (childItem.Fields[fieldName] != null && childItem.TemplateName == templateName)
{
using (new EditContext(childItem))
{
childItem[fieldName] = newValue;
}
}
if (childItem.HasChildren)
{
UpdateAllFieldsRecursively(childItem, templateName, fieldName, newValue);
}
}
}
}
}
// and below there is the call to recursive mehod
const string parentNode = "/sitecore/content";
var database = Sitecore.Context.Database;
var parentItem = database.GetItem(parentNode);
UpdateAllFieldsRecursively(parentItem, "Article", "Bucketable", "1");
2.PowerShell ISE. Execute the following code (you may need to modify that slightly according to your scenario):
cd 'master:/sitecore/content'
Get-ChildItem -Recurse . | Where-Object { $_.TemplateName -match "Article" -and $_.Fields["Bucketable"] -ne $null } | ForEach-Object {
$_.Editing.BeginEdit()
$_.Fields["Bucketable"].Value = "1";
$_.Editing.EndEdit()
""
}
This script goes recursively from /sitecore/content and updates Bucketable field for all Article template. Replace those values with whatever you need.
Here is a blog-post describing that: http://blog.martinmiles.net/post/mass-update-of-field-value-for-all-existing-items-of-certain-template-two-ways-of-achieving-result
Upvotes: 6