I need to update an Managed Metadata field Default Value in over 100 libraries .When i first set the value i used the script as shown below .But when i am trying to set the script default value to new value.Its not working .Can some one please guide me with this

 $taxField = $list.Fields.GetByInternalNameOrTitle("MyField")
[Microsoft.SharePoint.Client.Taxonomy.TaxonomyField] $txField = [Microsoft.SharePoint.Client.ClientContext].GetMethod("CastTo").MakeGenericMethod([Microsoft.SharePoint.Client.Taxonomy.TaxonomyField]).Invoke($global:ctx, $taxField)
    $taxField .DefaultValue = "-1;#MydataField|29ca0c72-1fc4-435f-a09c-28585cb5eac9"
    $taxField .Update()

I noticed one more thing its that the actual value is getting updated but when you go to the column default value settings it shows the old value .But if i upload a new document it actually has the new value .Is there a way that i can fix this .Also only for the managed metadata field it shows this folder for all the other ones it shows the library as shown below enter image description here

  • Check the type of $field. You may need to cast it to a taxonomy field type: $taxFld = [Microsoft.SharePoint.Client.ClientContext].GetMethod("CastTo").MakeGenericMethod([Microsoft.SharePoint.Client.Taxonomy.TaxonomyField]).Invoke($ctx, $field)
    – Bunzab
    Apr 12, 2017 at 20:10
  • Hi Bunzab .Actually i had edited the taxonomy field .The issue is this works when you use it for a new library but it doesnt work for an existing library which already has a default value
    – Anil
    Apr 12, 2017 at 20:20
  • Maybe try the DefaultValue.PopulateFromLabelGuidPairs method? msdn.microsoft.com/en-us/library/…
    – Bunzab
    Apr 12, 2017 at 20:29
  • That didnt do the trick :(
    – Anil
    Apr 12, 2017 at 21:36

1 Answer 1


You need to validate the TaxonomyValue first, what this does is it will ensure it's entered in the TaxonomyHiddenList which will give you a real id instead of -1(which means there's no id yet). This TaxonomyHiddenList id is what's really usd to set the value, the others are more descriptive.

In CSOM it looks like this:

TaxonomyFieldValue taxValue = new TaxonomyFieldValue();
taxValue.WssId = -1;
taxValue.TermGuid = term.Id.ToString();
taxValue.Label = term.Name;
//get validate string
var validateValue = field.GetValidatedString(taxValue);

Notice we set -1 here as well, as we don't know the id yet.

validateValue.Value is what you need to assign to your defaultValue

  • If you just need to "seed" the taxonomy hidden list, field.GetValidatedString is the action which does that for you May 5, 2017 at 8:15

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.