I have a document Library.
It contains many columns out of which I want to update the value for managed metadata column.
Suppose, the Value which I want to update is "My Value" and this value "My Value", exists in term store and also in Taxonomy Hidden List.
Below is my code to update the value:
#CAML Query to get Item From Library and Update
$spQuery = New-Object Microsoft.SharePoint.SPQuery
$spQuery.ViewFields ="<FieldRef Name='My_x0020_Prod' />";
$spQuery.ViewAttributes = "Scope='Recursive'";
$spQuery.Query = "<Where>
<Eq>
<FieldRef Name='Prod_x0020_ID' />
<Value Type='Text'>" + $prodID + "</Value>
</Eq>
</Where>"
$col=$list.GetItems($spQuery)
foreach ($item in $col)
{
if($item.Count -gt 0)
{
$item["My_x0020_Prod"] = "My Value"
$item.Update()
}
}
This code doesnt update the MMD item in the library and throws an error:
The given guid does not exist in the term store
Now, when I go back to the library and manually update the field for the MMD column, it works fine.
Programatically, this is not working and I think I am missing something.
Should I first get GUID from term store and then update the value in MMD?