Inconspicuous SharePoint Quirks #2

Mystery of the vanishing Publishing Hyperlink

Note: Publishing Hyperlink can be created as a site column “Hyperlink with formatting constraints”.

There seems to be a bug in Publishing Hyperlink field in SharePoint 2010 and it does not happen consistently. Lets say there is a List with Publishing Hyperlink site column. When you edit this list item, and focus on the url, a new “Link Tools” (green tab) appears in the editor. This brings additional properties to edit.

If you change the link value here, change and save, sometimes the link value disappears. Or if you click on Remove Link button, the “click here to add new link” disappears. I was able to verify this consistently in a totally clean site (SharePoint Server BuildĀ  14.0.5128.5000). This means you cannot add a link at all anymore. Your only option is to delete the item and add it again. Goodluck if the item is huge and/or has some relation to other lists!

Fortunately there is powershell, you can update the link directly. The trick is, while the regular Hyperlink is a string, the Publishing Hyperlink is an object. So you have to update the object properties first and set the object itself to the listitem and then update the list item. The following powershell code shows that:

Param([string]$site0="http://mysharepoint", [string]$list0="My List", [string]$itemKey0="Item Key", [string]$linkUrl0="http://newlink", [string]$desc0="New description", [string]$toolTip0="New Tooltip")

$site = Get-SPSite($site0)
$rootWeb = $site.rootWeb
$lists = $rootWeb.Lists
$list = $lists[$list0]
$items = $list.Items
$listItem = $items | Where-Object {$_.Name -eq $itemKey0}
$linkUrl = $listItem["Link Url"]
$linkUrl.NavigateUrl = $linkUrl0
$linkUrl.Description = $desc0
$linkUrl.ToolTip = $toolTip0
# this is the trick - set the object back to listItem
$listItem["Link Url"] = $linkUrl