0

I have to update field values to a particular item. Instead of changing the item's final version, I would like to create a new version and do my updates. For ex: if en(v2) is the latest, I need to create en(v3) and update my changes.

Is there any PowerShell script to update this?

2 Answers 2

4

You can use below PowerShell script for create a new item version and update field value

# Get All items under particular node with specific template name
$items = Get-ChildItem -Path "master:/sitecore/content/Home" -Recurse | Where-Object { $_.TemplateName -eq 'Template Name' }

# Loop all items 
foreach ($item in $items) 
{
    # Get item to update and create new item version 
   $itemToUpdate = Add-ItemVersion -ID $item.ID -Language en -IfExist Append
   $itemToUpdate.Editing.BeginEdit()
   $itemToUpdate.Fields["Button Text"].Value = "Button Text Mew"
   $itemToUpdate.Editing.EndEdit()
 
}

I tested it on my Sitecore instance and it's working as expected, please try it.

You can get more information about creating new item version from below URL as well. https://doc.sitecorepowershell.com/appendix/common/add-itemversion

1

You can follow this approach.

# Create a new item version by providing item ID
$item = Add-ItemVersion -ID "{56305117-8C9C-4C08-96D5-BB97A8E27419}" -Language en -IfExist Append

# Update this new item version fields
$item.Editing.BeginEdit()
$item.Fields["test"].Value = "new version of item"
$item.Editing.EndEdit()

Hope this will help.

Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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