Creation of multiple items and adding the content to it sometime becomes time consuming. Especially when you have large amount of data to be added in CMS from Excel (CSV) file. We also faced similar challenge where we need to create multiple items and added details to it from CSV file. It was a repetitive and time consuming task for us. For this obstacle we came up with Sitecore PowerShell script which will do this task for us. We just need to specify the location of path where we want to create items, Template ID and CSV file location. Sitecore PowerShell Script will run and create the items as per CSV file details.
Steps
Create CSV file and add details to it as shown below
Configure settings as per your requirement and run below PowerShell script in PowerShell script window.
Script
$itemPath="master:\content\home\TestFolder" #Location where items are created $templateID="{0087B3DC-A60A-4C46-B510-2A3A8F7C4D36}" #Template from items are created $importCSVPath = "C:\DemoImportFile.csv" #CSV file path #Import data from CSV file $importRows = Import-CSV $importCSVPath New-UsingBlock (New-Object Sitecore.Data.BulkUpdateContext) { foreach ($row in $importRows) { $itemName = $row.Field1 #Create Item $newItem = New-Item -Path $itemPath -Name $itemName -ItemType $templateID; #Add values in fields $newItem.Editing.BeginEdit() $newItem["Field1"] = $row.Field1 $newItem["Field2"] = $row.Field2 $newItem["Field3"] = $row.Field3 $newItem["Field4"] = $row.Field4 $newItem.Editing.EndEdit() Write-Host "Item Created: " $itemName } }
After script execution is successful items will be created in Content tree with CSV file details
Item Details
References
No comments:
Post a Comment