-
-
Notifications
You must be signed in to change notification settings - Fork 70
Description
Implemented as part of #1316
Expected Behavior
Post rename the item name using the PowerShell script it should update in the content tree with new name without refreshing the parent item or closing and opening
Please describe the expected behavior.
Actual Behavior
Displaying the OLD name in the Content Tree until user refresh the parent item in the content tree or close and opens it [again]
Please refer the below code for the reference which I am using
(` try
{
# Get context page name (old role name)
$array = $SitecoreContextItem.Paths.Path.Split("/")
$oldRoleName = $array[$array.Length - 1]
$fullRoleName = "sitecore"+$oldRoleName
# Get input name
$name = Show-Input "Please enter page name" -DefaultValue $oldRoleName
if (!$name) {
Exit
}
#Get SitecoreContextItem Item of the Microsite.
$ContextItemID = $SitecoreContextItem.ID.ToString()
$name = $name.Trim()
if ($name -eq "") {
Exit
}
# Check if page with the new name already exists
$basePath = "master:/content/BCG/Websites/Internal Information/DesignStudios/Home/Web platform/Client Proposal/"
$content = Get-Item -Path ($basePath + $name) -ErrorAction Ignore
if ($null -ne $content) {
Show-Alert "A page with this name already exists!"
Exit
}
# Rename page
$elevatedUser = Get-User -Identity "sitecore\DSWPAdmin"
New-UsingBlock (New-Object Sitecore.Security.Accounts.UserSwitcher $elevatedUser) {
$item = Get-Item -Path $SitecoreContextItem.Paths.Path
$item.Editing.BeginEdit()
$item.Name = $name
$item.Editing.EndEdit()
# Rename role
$newRoleName = $name
$newSiteName = $basePath + $name
# Get the existing role object
$oldRole = Get-Role -Name $fullRoleName
if ($oldRole) {
# Create a new role with the new name
$newRole = New-Role -Identity $newRoleName
$rights = @("item:read", "item:create", "item:write", "item:delete")
$rights | ForEach-Object { Add-ItemAcl -Path $newSiteName -AccessRight $_ -PropagationType Any -SecurityPermission AllowAccess -Identity $newRole }
# Transfer members and permissions from the old role to the new role
$members = Get-RoleMember -Identity $oldRole
$members | ForEach-Object { Add-RoleMember -Identity $newRole -Members $_ }
$roleToBeDeleted = Get-Role -Filter $fullRoleName
if($roleToBeDeleted.count -gt 0)
{
Remove-Role -Identity $roleToBeDeleted
}
Write-Host "Role has been renamed from '$oldRoleName' to '$newRoleName' successfully."
} else {
Write-Host "Role with the name '$oldRoleName' not found in Sitecore."
}
Show-Alert "As page and respective role have successfully renamed, previous URL will no longer work. Hence, please publish the microsite and then use the updated URL"
}
catch {
$errorMessage = $_.Exception.Message
Write-Host "An error occurred: $errorMessage"
}`)
Please describe the actual behavior.
Steps to Reproduce the Problem
Please include the version number of SPE and Sitecore.
Sitecore version is 10.1.1 and PS version is 5,
Please let me know how to resolve this issue.
-
Tested issue with clean install of Sitecore and the latest available version of SPE.
-
Asked questions on the Sitecore Slack Chat channel.
-
Reviewed questions and answers on the Sitecore Stack Exchange.