1

I am writing a Sitecore PowerShell Extensions script to determine which fields on a cloned item are unlinked from its original item. The easiest check is to compare the field value of the original and the cloned item. However, it is possible for the fields to have the same value but be unlinked, such as when the cloned item field is modified, saved, and then edited to be the same value as before.

What would the script look like?

1 Answer 1

1

You can use $field.ContainsStandardValue as follows:

function Find-UnlinkedFields {
  param(
    [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
    [Sitecore.Data.Items.Item]$ClonedItem
  )

  if (-not $ClonedItem.IsClone) {
    Write-Host "Item is not a clone"
    return
  }

  $unlinkedFields = New-Object System.Collections.Generic.List[Object]

  foreach ($field in $ClonedItem.Fields) {

    # OPTIONAL: skip standard fields. Could also perform other checks such as $field.Shared and $field.Unversioned
    if ($field.Name.StartsWith("__")) {
      continue
    }

    if ($field.ContainsStandardValue) {
      continue
    }

    $unlinkedFields.Add($field)
  }

  return $unlinkedFields
}

$unlinkedFields = Find-UnlinkedFields -ClonedItem (Get-Item -Path "master:/sitecore/content/path/to/clone")
$unlinkedFields | Format-Table -Property Name, Value

More information:

https://doc.sitecore.com/xp/en/developers/92/sitecore-experience-manager/determine-if-a-field-contains-standard-values.html

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.