Skip to main content

Featured post

XM Cloud content sync from prod to uat or UAT to prod step by step

When working with Sitecore, it’s common to need content synchronization across environments. Today, I’ll walk you through the steps to sync content from Production to UAT/TEST and vice versa. Steps to Follow 1. Set Up Your Workspace Create a folder on your computer where you will manage the script files and exported data. Open the folder path in PowerShell to begin scripting. We need to run some scripts in PowerShell to update the folder with the basic requirements for syncing content. PS C:\Soft\ContentSync> dotnet new tool-manifest PS C:\Soft\ContentSync> dotnet nuget add source -n Sitecore https://nuget.sitecore.com/resources/v3/index.json PS C:\Soft\ContentSync> dotnet tool install Sitecore.CLI PS C:\Soft\ContentSync> dotnet sitecore cloud login If the above error occurs, you will need to run a different command to resolve the issue. PS C:\Soft\ContentSync> dotnet sitecore init now, Again run above command to open and authenticate with XM Cloud. It will be there a...

PowerShell script to migrate content in Sitecore while taking specific item from CSV File

It's easy to read CSV file and migrate list of item which is specified in csv file. Upload CSV file at media item location . You can see below url which have mentioned.


$url = "https://tst-cdn.domain.net/-/media/domain/temp/ItemName.ashx?x=1"

$data = Invoke-WebRequest -uri $url  -UseBasicParsing | Select-Object -Expand Content

$TargetLangs = @("zh-cn","zh-hk","fr","de","it-it","es-es","th-th")

$csv = ConvertFrom-Csv $data

$sourceItemPath = "master:\sitecore\content\SLA\corporate\"

$destinationItemPath = "master:\sitecore\content\Shared Pages\Shared Press Releases\Corporate\"

$templateId = "{7B0B5195-5462-444E-8D5A-40941F2EC9B5}"

Write-Host "Get the source items and their fields"


ForEach ($csvItem in $csv) 

{

    $increment=$increment+1

    $csvItemName = $csvItem.URL.Replace("-"," ")

    if($csvItemName)

    {

    

    $sourceItem = Get-ChildItem -Path $sourceItemPath -Recurse -Language * | Where-Object { $_.TemplateID -eq $templateId  -and $csvItemName -contains $_.Name} | Select-Object -First 1


   

    $itemName = $sourceItem.Name 

    Write-Host $itemName

    if($sourceItem)

    {

     

    $parentItem = New-Item -Path $destinationItemPath -Name $itemName -ItemType "{1894730B-8450-4B97-8B97-DB29E88E1B9E}" -Language "en-gb" 

    


    $pressReleaseContentType = "{A0640481-9D25-49DD-B9A9-16C91112C800}"

    $shareTo ="{C2837D15-9A08-41E3-BEB1-4E020229F5BC}"


    Write-Host "Migrating item: $itemName"

    $parentItem.Editing.BeginEdit()


    $parentItem["navigationTitle"] = $sourceItem["Title"]

    $parentItem["pressReleaseTitle"] = $sourceItem["Title"]

    $parentItem["pressReleaseDescription"] = $sourceItem["MetaDescription"]

    $parentItem["pressReleasePublicationDate"] = $sourceItem["Publish Date"] 

    $parentItem["metaTitle"] = $sourceItem["BrowserTitle"]

    $parentItem["metaDescription"] = $sourceItem["MetaDescription"]

    $parentItem.Fields["pressReleaseContentType"].Value = $pressReleaseContentType

    $parentItem.Fields["__ShareTo"].Value =  $shareTo

   

   


    $parentItem.Editing.EndEdit() 

    

   

    

    $childFolder = New-Item -Path $parentItem.Paths.Path -Name "Page Content" -ItemType "{497AD3AE-D7C4-46B4-9FAD-0C9CECFB12C7}" -Language "en-gb" 

    

    $childItem = New-Item -Path $childFolder.Paths.Path -Name "Rich Text" -ItemType "{EFCFD8F6-5967-45F4-8F85-B5421928205D}" -Language "en-gb" 

    

    $childItem.Editing.BeginEdit()

    $childItem["description"] = $sourceItem["Body Text"]

    $childItem.Editing.EndEdit() 

    

    

    $renderingId = "{FD2ACD73-C1F6-4384-BAE4-525C644BEDB2}"

    $placeholderKey = "/abrdn-main/abrdn-article-body-{656698DD-376D-49F9-9687-9B49CEA6B3A6}-0"

    $dataSourcePath = $childItem.Paths.Path

   

    $renderingItem = Get-Item -Database "master" -Path $renderingId | New-Rendering -Placeholder $placeholderKey


    Add-Rendering -Item $parentItem -PlaceHolder $placeholderKey -DataSource $dataSourcePath -Instance $renderingItem  

    

}

else

{


Write-Host "Not Migrated item Name - $csvItemName"

}

}

Write-Host $increment

Write-Host "Item Created - " $incre

}


Comments

Popular posts from this blog

Set up Sitecore XM cloud

Working on Sitecore development projects typically involves two key steps. The first is the installation or deployment of the Sitecore instance, followed by the implementation or solution development. For those familiar with Sitecore XP/XM, deploying a vanilla Sitecore instance using tools like SIF/SIA could be time-consuming, often taking several hours due to prerequisites such as setting up Solr, SQL, and more. However, the introduction of Sitecore Experience Manager Cloud (XM Cloud) has revolutionized this process. XM Cloud serves as a fully managed, self-service deployment platform tailored for developers, effectively addressing the challenges of lengthy deployment times. It enables the deployment of a fresh Sitecore instance with a fully functional website in just a few clicks. In this blog post, I'll demonstrate how to deploy a demo website on the Sitecore XM Cloud. Subsequently, in the next blog post, I'll illustrate how effortlessly you can configure your local app deve...