0

I need to create a new site by duplicating/cloning existing site.

Requirements:

  • All datasource item on pages should point to new site.
  • All datasource item fields like droplink, multilist, generallink should be updated to point to new site.

Note that these are non SXA sites.

How do I clone so that new site will have not have any reference with existing site?

2
  • You need to do this one time or it should be context menu command like the one for SXA? Commented Dec 19, 2023 at 7:58
  • no context menu but want to keep scripts in place as it is repetitive process as more sites also needs to be cloned.
    – kartik
    Commented Dec 19, 2023 at 8:13

1 Answer 1

1

You can start with the following scripts and then modify it to achieve what you need.

# Specify the source and destination paths
$sourcePath = "/sitecore/content/Path/To/SourceItem"
$destinationPath = "/sitecore/content/Path/To/DestinationItem"

# Copy the item and its descendants
Copy-Item -Path $sourcePath -Destination $destinationPath -Recurse

After copying all the items from the old path to the new path you can work on updating the fields. You only need to update the fields those are having the old site item ID like DropLink, General Link, etc.

# Update fields to point to the new site path
$item.Fields | ForEach-Object {
    if ($_.type -eq "<your field type>") 
    {
       # Get the value of the field that should be the raw value of item id
       $itemValue = $field.Value
    
       # Get the item and it's path
       $oldItem = Get-Item -ID $itemValue
       $itemPath = $oldItem.Paths.FullPath

       # replace the path with new Site and get the ID 
       $newItemPath = $itemPath.Replace("<old site name>", "<new site name>")
       $newItem = Get-Item -Path "master:$newItemPath"

       $item.Editing.BeginEdit()
       $item[$_.Name] = $newItem
       $item.Editing.EndEdit()
    }
}

I have written this script to give you an idea of how you can proceed with this and you can further modify this as per your requirement.

Hope this helps.

2
  • is there way to update General link fields also to point internal links to new site
    – kartik
    Commented Dec 20, 2023 at 12:48
  • Check this thread and you will get idea that how you can update the attributes of general link and this will give you some idea. stackoverflow.com/questions/50978123/… Commented Dec 20, 2023 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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