Is there a way that i can Query Solr to get data based on a template. Then foreach of that data do a Sitecore Getitem and Update a field's value.
1 Answer
I would first start with the following commands:
- Find-Item : Use this to query the index
- Initialize-Item : Use this to convert the data from the index into Sitecore items
- The items that come back can then be managed directly like seen here
Example: The following example finds all items in the master index inheriting from the "Sample Item" template. Those items are retrieved and the title field is updated with the current date.
$criteria = @(
@{Filter = "Equals"; Field = "_templatename"; Value = "Sample Item"; }
)
$props = @{
Index = "sitecore_master_index"
Criteria = $criteria
}
$items = Find-Item @props | Initialize-Item
foreach($item in $items) {
$item.Title = "Current time: $(Get-Date)"
}