I posted this on https://github.com/SharePoint/sp-dev-docs but was kindly asked to post here.
Please specify what version of the library you are using: [1.2.8]
Please specify what version(s) of SharePoint you are targeting: [SP2013, 15.0.0.0]
I'd like to set the default value of a managed metadata column after the creation of a list.
I've been able to set a single text line column default value with the following code:
let defaultValueSet = await web.lists.getByTitle('My list Title')
.fields
.getByTitle('My column name')
.update({
DefaultValue: "My default value"
});
but when I try for a managed metadata column, it won't work.
Here is the syntax I use:
let defaultValueSet = await web.lists.getByTitle('My list Title')
.fields
.getByTitle('My managed metadata column name')
.update({
DefaultValue: "-1;#Managed metadata value|c7e3a435-xxxx-xxxx-xxxx-286bb0e8bc20" // guid of the term label(not termset)
}, "SP.Taxonomy.TaxonomyFieldValue");
I've also replace -1 by the corresponding WssId, no success.
I've also tried the following syntax:
...
.update({
DefaultValue:{
__metadata:{
"type": "SP.Taxonomy.TaxonomyFieldValue" },
Label: "Managed metadata value",
TermGuid: "c7e3a435-xxxx-xxxx-xxxx-286bb0e8bc20",
WssId: -1,
}
}
})
Again, I've also replace -1 by the corresponding WssId, no success.
Any help much appreciated.
Thank you for your feedback!
Hi @UMAknow-Patrick.
EDIT: I didn't read properly what you wanted to do it seems, so scratch this :)
Have you looked at the helper methods that @patrick-rodgers created? https://pnp.github.io/pnpjs/sp-taxonomy/docs/utilities/#setitemmetadatafield
I made a post a while back on this topic as well: https://simonagren.github.io/pnpjs-update-managed-metadata/
Let me know if it helped or if we need to help further :)
Hi @simonagren,
Unfortunately does not work for setting the default value of a field.
Thanks for helping
Oh ok. Can look in to this later today
Ok @UMAknow-Patrick,
First off you need the correct WssId for setting the default value, -1 wont work.
So make sure you have the correct WssId, which you seemed to have under control.
First I set a default value to this, just to try this out:

Then I ran this update:
const updField = await sp.web.lists.getByTitle('Testing').fields.getByTitle('MetaField').update({ DefaultValue: "3;#Term1|248e5d6a-6a3e-4292-a1d6-2632dd59a892" });
And voila:

Let me know if this solves your problem :)
That works ! Thank you @simonagren.
2 notes:
Thanks for the quick answer.
Thanks, looks like we can close this. Nice work @UMAknow-Patrick and @simonagren
Most helpful comment
That works ! Thank you @simonagren.
2 notes:
Thanks for the quick answer.