0

How can I create new language version item for linked items of page using Sitecore PowerShell Extensions?

Script for items language version creation:

#Create new items with new language
function Create-ItemsLangVersion {
    param(
        [string]$path,
        [bool]$publish,
        [bool]$setToDraft,
        [bool]$isIdpItem
    )
    
    $items = @()
    
    New-UsingBlock (New-Object Sitecore.Data.BulkUpdateContext) {      
        
        $items += Get-Item $path 
        $items += Get-ChildItem $path -Recurse 
   
        #For each selected item and child items, set new language definition
        foreach($baseItem in $items) {
            
            #For each selected target languages
            foreach($language in $newLang){
                
                $targetLangItem = Get-Item -Path $baseItem.Paths.FullPath  -Language $language
                if(($baseItem -ne $null -and $baseItem.Versions.GetVersions().Count -gt 0) -and ($targetLangItem -eq $null -or $targetLangItem.Versions.GetVersions().Count -eq 0))
                {
                    Add-ItemLanguage -Item $baseItem -Language $baseLang -TargetLanguage $language -IfExist Skip
                    $baseLangItemId = $baseItem.Id.Guid.ToString("B")
                    $newLangItem = Get-Item -Path master: -Language $language -Id $baseLangItemId
                    
                    Copy-FinalRenderings $baseItem $newLangItem
                    
                    Write-Host "New language version created for item:" $baseItem.ID " - " $baseItem.Name
                    
                    if($publish -eq $true)
                    {
                        Publish-NewLangItem $newLangItem
                    }
                    if($setToDraft -eq $true)
                    {
                        if($isIdpItem -eq $true)
                        {
                            Update-WorkflowToIdpDraft $newLangItem
                        }
                        else
                        {
                            Update-WorkflowToDraft $newLangItem
                        }
                    }
                }
                else
                {
                    Write-Host "Skipped item:" $baseItem.ID " - " $baseItem.Name
                }
            }
        }
    }
}

So if content for example have list of options, or dropdown values list, I also need to create item for each of them in dropdown list.

4
  • Can you please provide more context on what you want to achieve? If possible, can you share your script snippet on what you have already achieved Apr 15 at 7:44
  • Sure, I updated the context!
    – user11621
    Apr 15 at 8:02
  • creating items in the list / dropdown, you mean static ones or do you have a datasource that points to a container that contains those items to be listed? Apr 15 at 8:03
  • both, static ones and when you have a data source that points..
    – user11621
    Apr 15 at 8:06

1 Answer 1

0

You can use the following, which will give you all the linked items of an item like image, droplink, link, etc.

The script you will use is this.

Get-Item -Path "master:" -Uri "sitecore://master/<Your Item ID>"  | Get-ItemReference -ItemLink  

So to test this, I have these fields on an item.

enter image description here

So when I run this, it will give me the output for a template, and two drop links.

SourceItemLanguage          :
SourceItemVersion           : 0
TargetItemLanguage          :
TargetItemVersion           : 0
SourceDatabaseName          : master
SourceFieldID               : {0D83E59A-C3F1-41BE-81B2-762D35E0799F}
SourceItemID                : {089FB61A-D804-4205-AFB8-BC7099C7AABD}
TargetDatabaseName          : master
TargetItemID                : {7313C9A1-836B-4871-899E-2618BB7DA955}
TargetPath                  : {7313C9A1-836B-4871-899E-2618BB7DA955}
SourceIsLanguageIndependent : True

SourceItemLanguage          :
SourceItemVersion           : 0
TargetItemLanguage          :
TargetItemVersion           : 0
SourceDatabaseName          : master
SourceFieldID               : {00000000-0000-0000-0000-000000000000}
SourceItemID                : {089FB61A-D804-4205-AFB8-BC7099C7AABD}
TargetDatabaseName          : master
TargetItemID                : {E5781591-1FB0-4C23-8197-068911765AD4}
TargetPath                  : {E5781591-1FB0-4C23-8197-068911765AD4}
SourceIsLanguageIndependent : True

SourceItemLanguage          :
SourceItemVersion           : 0
TargetItemLanguage          :
TargetItemVersion           : 0
SourceDatabaseName          : master
SourceFieldID               : {24171BF1-C0E1-480E-BE76-4C0A1876F916}
SourceItemID                : {089FB61A-D804-4205-AFB8-BC7099C7AABD}
TargetDatabaseName          : master
TargetItemID                : {7E8D1A67-55A4-4037-BCE0-B7C4150A3C10}
TargetPath                  : {7E8D1A67-55A4-4037-BCE0-B7C4150A3C10}
SourceIsLanguageIndependent : True

Now you can create a loop on these items and then use the following script to create a language version.

Add-ItemLanguage -Item $Item -Language "en-US" -TargetLanguage "en" -IfExist OverwriteLatest                
2
  • Thank you for answer!
    – user11621
    Apr 15 at 8:16
  • Update: Items must be selected, and rebuild link database need to be done, in order to this works properly.
    – user11621
    Apr 15 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy