I am running power shell script to bind treelist data in both language english & french.even if i change language am getting only English content in french .please review my script and let me know what am missing?

       #Upload the file on the Server in temporary folder
       #It will create the folder if it is not found
         $TargetLanguage = "fr-CA"
         $Language = "en"

      $dataFolder = [Sitecore.Configuration.Settings]::DataFolder
      $tempFolder = $dataFolder + "\temp\upload"
      $filePath = Receive-File -Path $tempFolder -overwrite
      $templatePath = "Chartwell/Project/Website/Page Template/Property" 

     $contentPath = "master:/content/Web3/Content Shared Folder/Property"

     if($filePath -eq "cancel"){
      exit
     }

       #Property Section
      $AllProperties = Get-ChildItem -Path 
          "master://sitecore/content/Web3/Content Shared Folder/Property 
           Page" -Recurse

     #Dining Section            
      $AllDining = Get-ChildItem -Path 
    "master://sitecore/content/Web3/Content Shared Folder/Dining Service" - 
     Recurse



        $resultSet =  Import-Csv $filePath

      $rowsCount = ( $resultSet | Measure-Object ).Count;

if($rowsCount -le 0){
    Remove-Item $filePath
    exit
}

  Write-Log "Bulk Update Started!";
        New-UsingBlock (New-Object Sitecore.Data.BulkUpdateContext) {
     foreach ( $row in $resultSet ) {

    $PropertyID = $row."PropertyID";    #Here
    $Property = $AllProperties  | Where-Object { $_."Legacy ID" -eq 
         $PropertyID };

        if ($Property){

        $DiningDataID = $row."DiningDataID";
        $DiningData = $AllDining   | Where-Object { $_."Legacy ID" -eq 
            $DiningDataID };

        $ID = $Property."Dining Service"
        if($ID -eq '')
        {
            $ID = $DiningData.id
        }
        else
        {               
            $ID = $ID + "|" +$DiningData.id
        }           

        $Property.Editing.BeginEdit();
        $Property["Dining Service"] = $ID;  #Here
                   #FrenchSection
        $langAdd = Add-ItemLanguage -Item $Property -Language $Language -TargetLanguage $TargetLanguage -IfExist Skip;
                 Write-Log $Property.id 
        $Property.Editing.EndEdit();
                    $ItemPath = $ContentPath + "\" + $Property 
        $NewcurrentItem = Get-Item -Path "master:" -Id $Property.id -Language $TargetLanguage
        $NewcurrentItem.Editing.BeginEdit();
        $NewcurrentItem["Dining Service"] = $ID; 

        $NewcurrentItem.Editing.EndEdit();

    }
    else {
        $logThis =  "Couldn't find Property with ID: " + $PropertyID + " Property Item: " + $Property;
        $logThis;
        Write-Log $logThis;
    }
}
}
$logInfo = "Bulk Update is Completed!";
$logInfo
Write-Log $logInfo

    Remove-Item $filePath

how to change language of the $AllDining ?

Add Language parameter to your Get-ChildItem cmdlet call

Example:

Get-ChildItem . -Language "ja-JP"

in this case, ja-JP is a language code. Use the want that you need.

If you need the same item but in every language use *

Get-ChildItem . -Language "*"
  • how to switch it ?incase of two language am i need to write script twice for english one script and french another script – sitecore-u9 Apr 6 at 18:48
  • You can use variable that you have on the top. Get-ChildItem . -Language "$TargetLanguage" – Alan Płócieniak Apr 6 at 19:01
  • i changed but now am having english data twice in french version. – sitecore-u9 Apr 6 at 19:11
  • could you please check my updated script am very new to powershell script – sitecore-u9 Apr 6 at 19:11
  • please check this syntax $AllDiningFR = Get-ChildItem -Path "master://sitecore/content/Web3/Content Shared Folder/Dining Service" -Language $TargetLanguage – sitecore-u9 Apr 6 at 19:18

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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