SharePoint Error: “The page you selected contains a list that does not exist” or “The SPListItem being updated was not retrieved with all taxonomy fields”

If you add a managed metadata field to a view in SharePoint, you might get the cryptic error message “The page you selected contains a list that does not exist”.

3RVCU

Variations of this error can be seen when you, either using a browser or via code, try to update a list item and receive the following error: "The SPListItem being updated was not retrieved with all taxonomy fields”.

2015-11-24_12-03-33

These issues can occur when the managed metadata column, either on site level on list level, is missing the connection to the Term Store or the lookup fields to the hidden list “TaxonomyHiddenList”. Luckily, this can be fixed by a bit of PowerShell.

First, fetch the field from the web or from the

#PARAMETERS
$siteUrl = "https://sptest.lekman.com"
$termStoreName = "Managed Metadata Service"
$termGroupName = "Navigation"
$termSetName = "Global Links"
# Load SP PowerShell
if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
write
-host " Loading SharePoint PowerShell add-ins..." -ForegroundColor Green
[System.Reflection.Assembly]
::LoadWithPartialName("Microsoft.SharePoint") | Out-Null
Add
-PSSnapin Microsoft.SharePoint.PowerShell | Out-Null
write
-host
}
#FUNCTIONS
function Create-TermGroup($termStore, $termGroupName) {
$termGroup = $termstore.groups[$termGroupName];
if ($termGroup -eq $null) {
write
-host " Term store group not found. Creating... " -NoNewline -ForegroundColor Yellow
$termGroup = $termStore.CreateGroup($termGroupName);
$termStore.CommitAll()
write
-host "Done!" -ForegroundColor Green
}
return $termGroup
}
function Create-TermSet($termStore, $termGroup, $termSetName) {
$termSet = $termGroup.TermSets[$termSetName]
if ($termSet -eq $null) {
write
-host " Term set not found. Creating... " -NoNewline -ForegroundColor Yellow
$termSet = $termGroup.CreateTermSet($termSetName)
$termStore.CommitAll()
write
-host "Done!" -ForegroundColor Green
}
return $termSet
}
function Connect-MetaDataField($targetField, $site) {
try {
write
-host " Updating taxonomy field..." -NoNewline -ForegroundColor Yellow
$taxField = [Microsoft.SharePoint.Taxonomy.TaxonomyField]$targetField
$taxonomyList = $site.Rootweb.Lists["TaxonomyHiddenList"]
$taxField.SspId = $termStore.Id
$taxField.TermSetId = $termSet.Id
$taxField.Update() | Out-Null
$taxField.SchemaXml = $taxField.SchemaXml.Replace($taxField.LookupWebId.ToString(), $site.RootWeb.Id.ToString()).Replace($taxField.LookupList.ToString(), $taxonomyList.ID.ToString("B"))
$taxField.Update() | Out-Null
write
-host "Done!" -ForegroundColor Green
} catch {
write
-host "Failed!"$_ -ForegroundColor Red
}
}
#EXECUTION

$asc = Start-SPAssignment;
$site = Get-SPSite $siteUrl
$session = new-object Microsoft.SharePoint.Taxonomy.TaxonomySession($site) -ErrorAction Stop
$termStore = $session.TermStores[$termStoreName]
if ($termStore -eq $null) {
write
-host "Unexpected error. Managed Metadata Service not found." -ForegroundColor Red
}
else {
write
-host " Connected to Metadata Store" -ForegroundColor Yellow
$termGroup = Create-TermGroup $termStore $termGroupName
write
-host " Term group is"$termGroup.Name
$termSet = Create-TermSet $termStore $termGroup $termSetName
write
-host " Term set is"$termSet.Name
$targetField = $null
try {
$targetField = $site.RootWeb.Fields.GetFieldByInternalName("YourFieldName")
} catch {}

if ($targetField -eq $null) {
write
-host "Unexpected error. Managed metadata field is not installed." -ForegroundColor Red
}
else {
Connect
-MetaDataField $targetField $site
}
}

Stop
-SPAssignment $asc

Hope this helps!