I have a script that copies a page with renderings from a set language to 1 or more other languages that are selected by checkboxes. The whole script works when i run it in the ISE, but when I run it from the Context Menu it doesn't seem to find any renderings and therefore it only copies the page (with renderings), however the data source items are not copied. Thankful for any help I can get!
$sourceItem = get-item .
$sourceLanguage = $sourceItem.Language.Name
$options = @{
"Danish"="da-DK"
"Norwiegan"="nb-NO"
"German"="de-DE"
}
$result = Read-Variable -Parameters `
@{ Name = "languageItem"; Title="Choose The Target Language";
Options=$options;
editor="check"} `
-Title "Create Language Version Script" -Width 400 -Height 200 -
OkButtonName "Create Version" -CancelButtonName "Cancel" -ShowHints
if($result -ne "ok")
{
Exit
}
function Add-TranslationForItemAndDataSources {
[CmdletBinding()]
param(
[Item]$Item,
[string]$Language,
[string]$TargetLanguage
)
# adds new version of the page
Add-ItemLanguage -Item $item -Language $Language -TargetLanguage
$TargetLanguage -IfExist Skip
Get-Rendering -Item $item -FinalLayout -Device(Get-LayoutDevice -Default) |
Where-Object { -not [string]::IsNullOrEmpty($_.Datasource)} ` |
ForEach-Object {
Write-Host $_.Datasource
$datasourceItem = Get-Item "$($item.Database):" -ID $_.Datasource
Write-Host "$($item.Database):"
Write-Host $datasourceItem.Name
Add-ItemLanguage -Item $datasourceItem -Language $Language -
TargetLanguage $TargetLanguage -IfExist Append
}
}
foreach ($i in $languageItem)
{ Add-TranslationForItemAndDataSources -Item $sourceItem -Language "sv-SE" -
TargetLanguage $i }
write-host 'Script ended'
ISE editing session
toDispose session ...
and see if it still works in ISE, maybe you've got some temp value which is missing while executing script in different context. Add more log messages and simply debug it step by step. UseWrite-Host
to display states in different places and compare it with those from ISE.