Set Default managed metadata column
Category
- [x] Question
- [ ] Typo
- [ ] Bug
- [ ] Additional article idea
Expected or Desired Behavior
I'd like to set the default value of a managed metadata column after the creation of a list.
Observed Behavior
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 tried the following syntax:
...
.update({
DefaultValue:{
__metadata:{
"type": "SP.Taxonomy.TaxonomyFieldValue" },
Label: "Managed metadata value",
TermGuid: "c7e3a435-xxxx-xxxx-xxxx-286bb0e8bc20",
WssId: -1,
}
}
})
Any help much appreciated.
Thanks for your contribution! Sharing is caring.
Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.
Hi @UMAknow-Patrick
To make it works I think you need to have/get a real WssId for a term. Have you tried it? I had the same issue before, it was working only with the real WssId. I used the next format for the default value wssId;#lavel|guid and wrote helper to get the WssId from the 'TaxonomyHiddenList' list (with some hacks if a term is new and no WssId for it).
Looks like you're working with PnPJS... correct? If so, please post the question in their repo as it's more on topic and you'll get more specific response: https://github.com/pnp/pnpjs
If I'm misunderstanding this, please feel free to respond and we can reopen the issue.
Hi @akukharevich, I tried this also (with wssId not -1) and I still got the same error:
Incompatible type kinds were found. The type 'SP.Taxonomy.TaxonomyFieldValue' was found to be of kind 'Complex' instead of the expected kind 'Entity'.
I get this error with both syntax. I forgot to specify I'm working on SP2013. My customer is migrating to SP2016 in a couple of weeks, I'll see if anything changes.
Hi @andrewconnell, thanks for the tip, I'll re-post on pnpjs.
Find the correct syntax and solution on pnpjs: https://github.com/pnp/pnpjs/issues/506#issuecomment-464195781
Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues