0

I have a slightly strange situation where essentially the Standard values for a droptree field have been set incorrectly for quite some time on a number of page templates. The 'Content Type' field should have been set to an empty value instead of an Item Id.

This has resulted in the initial value being set incorrectly for these page items. On some pages content editors have updated the value of 'Content Type' to an different one in the list. On other pages the 'Content Type' has been left 'as is' so it is falling back to the incorrect standard values 'Content Type' value.

I need to fix the initial value set on the standard values for 'Content Type' by setting it to empty (Validation exists on the field to ensure Content editors select a value for this field on page creation so an empty standard value for this field is desired). BUT I need to not affect any existing pages where an 'Content Type' value has not been set.

This is where the problem lies, once I set the 'Content Type' standard value to empty the pages that have had no field value set for 'Content Type' are using the standard value and are therefore showing Empty, instead of the value that was originally set for that page template in the Standard values.

My understanding is that this is how standard values are expected to work, so it's not that they are not working correctly. I think what I actually wanted here was the old school 'Default Values' instead as that would have copied the values of the 'Content Type' field to the pages.

The only solution I can think of for this is to write some SPE to go through every page and check if it has a value set and if not then set it to the standard values value for the page template and then save it. This is less than ideal as it will take some time to test and run. I've written an SPE script to test this and it doesn't seem to work (unless I change the 'Content Type' to different value to the Standard Value 'Content Type') but I'll post a separate question on that if I need to go the SPE route.

Does anyone have any simpler solutions to this issue?

I know there is a 'reset blank' option but I don't think that will help here.

Other info: We are on Sitecore 8.2 update 7.

0

I try reproduce your issue in my local site. I had the result like this: After you edit any field with item created from template, it doesn't auto changed when update template. So I try "reset field", it will return page to inherit template again.

enter image description here

I used Sitecore 9.0.2

  • Thanks for your input on this but I don't think you get the issue I'm having exactly. If you read up on how standard values work then you will see that I need to update the field to a different value to the standard value and then back to the same value as the standard value in order for my item to no longer use the standard value: doc.sitecore.com/developers/92/sitecore-experience-manager/en/…. I have a working SPE script to solve this now which I'll share soon. – Adam Seabridge Nov 7 '19 at 15:52
0

It took a while to figure this out but In the end (after reading this: https://doc.sitecore.com/developers/92/sitecore-experience-manager/en/how-to-determine-if-a-field-contains-standard-values.html) I realised what I needed to do was update the value to a different value and then back again. The key to this is forcing Sitecore to update the .ContainsStandardValue property of a field which Sitecore uses to track if a field is using the Standard Value or not. This was the SPE script I came up with to solve this:

$templateIds = 
'{565F2D63-1359-726C-AB77-F3DA34C90AD0}', 
'{3465B346-3B37-8E40-AB70-31E17F4F38H4}', 
'{78309E9F-49A6-91C9-9DC3-73F340CE6690}'

$global:usingStandardValues = 0
$global:notUsingStandardValues = 0
$global:updateContentTypeField = $false
$global:fieldName = "content type"

Write-Host "---Starting Update Content Types Script---" -ForegroundColor DarkCyan
Write-Host "Update Content Type Field Setting = $($global:updateContentTypeField)"
Write-Host "Getting Pages to update..."

$pages = Get-ChildItem -Path "/sitecore/content/Site1/Home" -Recurse | Where-Object {$templateIds -contains $_.TemplateID} 

foreach($page in $pages){
    $contentTypeId = $page["$($global:fieldName)"];
    $contentType = Get-Item -Path "master:/$($contentTypeId)";

    #check if field is using the standard values or not
    $contentTypeField = Get-ItemField -Item $page -ReturnType Field -Name "content type"

    if ($contentTypeField.ContainsStandardValue){

        $global:usingStandardValues +=1;
        Write-Host "$($page.Name) is using standard value - $($contentType.Name) ($($contentTypeId))." -ForegroundColor Yellow

        if($global:updateContentTypeField){

            New-UsingBlock (New-Object Sitecore.Data.BulkUpdateContext) {
                #temp update to temp item value to force "ContainsStandardValue" change
                $page.Editing.BeginEdit()
                $page["$($global:fieldName)"] = "{1F342E82-HF89-876D-92AF-63F05CBF2636}" #temp content type item
                $page.Editing.EndEdit() | Out-Null
                Write-Host "Content Type Updated To Temp Content Type Item: 1F342E82-HF89-876D-92AF-63F05CBF2636 - $($page.Paths.FullPath)" -ForegroundColor DarkGreen

                #now set it back to same content type value again
                $page.Editing.BeginEdit()
                $page["$($global:fieldName)"] = $contentTypeId
                $page.Editing.EndEdit() | Out-Null
                Write-Host "Content Type Updated To Content Type Item: $($contentType.Name) - $($contentTypeId)" -ForegroundColor Green
            }
        }
    }
    else{
        $global:notusingStandardValues +=1;
        Write-Host "$($page.Name) - is NOT using standard value - Skipping Page Item."  -ForegroundColor Magenta
    }
}

Write-Host "---Script Completed---" -ForegroundColor DarkCyan
Write-Host "-----------------------------------------"
Write-Host "Pages Using standard values for Content Type field: $($global:usingStandardValues)"
Write-Host "Pages Not using standard values for Content Type field: $($global:notUsingStandardValues)"

Once the script has run the ContainsStandardValue for the field is false for all items and therefore the Page template can be updated without affecting the value of this field for the items using the Page Template.

I've also blogged about this here:

https://www.flux-digital.com/blog/fixing-standard-values-without-affecting-existing-content/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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