I am currently using the Sitecore Powershell Broken Links Report to find and delete broken links. Using the Broken Links Report, I have been able to locate the broken links. I can't seem to delete them however. Here is the code segment I am using to delete broken links (from Sitecore PowerShell GitHub):

    foreach($brokenItem in $items) {
        $item = Get-Item -Path "master:" -ID $brokenItem.ID
        Write-Host "Removing broken links from $($item.ItemPath)"

        $brokenFieldName = $brokenItem."Broken Link Field"
        $brokenLink = $brokenItem.BrokenLink

        if($brokenLink) {
            $fieldItem = $item.Fields[$brokenLink.SourceFieldID]
            $field = [Sitecore.Data.Fields.FieldTypeManager]::GetField($fieldItem)

            $item.Editing.BeginEdit() > $null
            $field.RemoveLink($brokenLink)
            $item.Editing.EndEdit() > $null

    }
}

There are specific fields I've tried to delete links from fields such as a treelist, drop tree, image and general link fields. However, when I check the item and item field to see if the links have been deleted after I run the script, the broken links are still in the item field and in Navigate->Links for the item. I am wondering if RemoveLinks() can only delete links from certain field types or from fields that store links in a certain format (such as XML, GUIDs, pipe-separated GUIDs, or Sitecore paths).

I have also tried to reset the item field altogether using:

$item | Reset-ItemField -Name $brokenFieldName

And that has also failed to remove the links. How is RemoveLinks() removing links from items? And does the ability to remove links depend on the field type or storage format?

  • If you rebuild the link database, does this issue still occur? If you remove the link using the Sitecore interface does this issue still occur? – Michael West Aug 9 at 21:00
  • I have run into issues with rebuilding the link database, but currently working on rebuilding it eventually. I can update this once I successfully rebuild the link database. When I remove the link manually from a general link field the field itself is cleared but the broken link still appears under Links in the Navigate ribbon. – Ariana Aug 9 at 21:54

Recently came into the same problem, seems like only certain types of reference is stored in the links database. Tree, TreeList, and File will not be stored.

https://sdn.sitecore.net/Articles/Media/Referencing%20Binary%20Items/Field%20Types.aspx?lg=sdn5print

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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