I need to copy item field data from en language to all other available languagesin all versions. Any powershell script of achieving this.
-
doc.sitecorepowershell.com/working-with-items/item-languages– Michael WestCommented Aug 22, 2020 at 19:01
-
@MichaelWest these script create a new version doesn't copy value to existing version. I am looking for something that copy value to existing version– kartikCommented Aug 22, 2020 at 19:10
-
I just want to clarify that the Add-ItemLanguage command does copy existing values. You can configure if you do not want this with the -DoNotCopyFields flag. Additionally, you can specify which fields you do not want to have copied by using -IgnoredFields– Koen HeyeCommented Jul 28, 2021 at 15:16
Add a comment
|
1 Answer
Probably the below script can help you. The comments are added to the script to make each step obvious. You can do modifications to it to suit your purpose -
#Get all language versions defined in System/Languages
$languages = Get-ChildItem /sitecore/System/Languages -recurse | Select $_.name | Where-Object {$_.name -ne "en"} | Select Name
#Ensuring correct items are updated by comparing the template ID
$items = Get-ChildItem -Path "/sitecore/<your item location>" -Recurse |
Where-Object {'<item template id>' -contains $_.TemplateID}
#Bulk update context to improve performance
New-UsingBlock (New-Object Sitecore.Data.BulkUpdateContext) {
foreach($item in $items) {
foreach($language in $languages) {
$languageVersion = Get-Item -Path $item.Paths.Path -Language $language.Name
#Check if language version already exists
if($languageVersion -eq $null){
Write-Host "Creating "$language.Name" version for "$item.Name
Add-ItemLanguage -Item $item -Language "en" -TargetLanguage $language.Name -IfExist OverwriteLatest
}
}
}
}
The script is also available at my blog.