pnpcore
pnpcore copied to clipboard
Taxonomy Value handling relies on FieldType instead of AllowMultipleValues
Category
- [x] Bug
Describe the bug
When reading or writing Taxonomy Fields to code check for the FieldType TaxonomyFieldType or TaxonomyFieldTypeMulti to determine if to expect a single Value or a List of Values. Unfortunately a User can create the Field as TaxonomyFieldType and turn on multivalue support after or vice versa create it as TaxonomyFieldTypeMulti and turn multivalue support off.
In order to handle values correctly you have to check Field Property AllowMultipleValues.
Steps to reproduce
- Create a List with Field of Type TaxonomyFieldType and then turn multivalue support on after wards.
- Add Select multiple Values from Taxonomy Store
- Try to Read Values with pnpcore - you will get no values
- Try to Add a Value to the Field - it will not return a failure but value is not added
Expected behavior
Respect AllowMultipleValues setting when Read, Update Taxonomy Fields
Environment details (development & target environment)
With DEV Branch of today (Feb 16, 2024) Console App to NET Framewotk 6 to verify issue
Additional context
It seems that the current modern UI does actually change the FieldType according to the setting of AllowMultipleValues.
@jansenbe Source of Issue unclear. Change in UI Modern and Classic changes today the FieldType according to the selection of AllowMultipleValues when updating Field-settings. However it's possible to create a Taxonomy Field using Field SchemaXML with FieldType TaxonomyFieldType and AllowMultipleValues=true which gets created and behaves after in UI excatly as a Field of Type TaxonomyFieldTypeMulti.
In PnPFramework i can find that we handle this situation - that's why i thought it could be something from the past replicated with old PnPTemplates. After all not sure if we should fix it here or it's better to just throw a error - at least it sould not silently fail.
@czullu : can you provide context on how this is handled in PnP Framework, will save some time for a possible fix
@jansenbe Hope this is what you are looking for:
Export: https://github.com/pnp/pnpframework/blob/dev/src/lib/PnP.Framework/Provisioning/ObjectHandlers/ObjectListInstanceDataRows.cs TokenizeValue called for Export seems to act on FieldType only - therefore we should not export the issue
Provision: https://github.com/pnp/pnpframework/blob/dev/src/lib/PnP.Framework/Provisioning/ObjectHandlers/ObjectListInstanceDataRows.cs We use https://github.com/pnp/pnpframework/blob/dev/src/lib/PnP.Framework/Provisioning/ObjectHandlers/Utilities/ListItemUtilities.cs UpdateListItem in case staring 409/410 => if the Template value has a separator and AllowMultipleValues is true on SP-Field then we will set the Terms independent of the FieldType.
(https://github.com/pnp/pnpframework/blob/dev/src/lib/PnP.Framework/Provisioning/ObjectHandlers/ObjectField.cs) Provision: CreateField: we use the FieldXML =>ValidateTaxonomyFieldDefaultValue ==>GetTaxonomyFieldValidatedValue => we read the actual setting of AllowMultipleValues
Extract: Check if Type starts with TaxonomyField uses TokenizeTaxonomyField in ObjectHandlerBase does not seem to handle default values - no issue here
https://github.com/pnp/pnpframework/blob/dev/src/lib/PnP.Framework/Provisioning/ObjectHandlers/ObjectListInstance.cs Provision: Uses ProcessFieldDefaults which refers to ObjectField.GetTaxonomyFieldValidatedValue Extract: Cloud not find default values
The Helpers in TaxonomyExtensions and ObjectField are also checking for AllowMultipleValues. I think the reason is, that in Namespace Microsoft.SharePoint.Client.Taxonomy there is only TaxonomyField and that's why we only check for the boolean as we would then call either SetFieldValueByValue/SetFieldValueByValueCollection or to get TaxonomyFieldValueCollection taxonomyValues = new TaxonomyFieldValueCollection(item.Context, null, taxonomyField);.
@czullu : why was this closed again? I did not yet had to change to work on it, is this not needed anymore?
@czullu : why was this closed again? I did not yet had to change to work on it, is this not needed anymore?
@jansenbe i closed it because the only way i found that you can get into the situation where you end up with having FieldType TaxonomyFieldType and AllowMultipleValues=true is by adding a wrong XML-definition with Add-PnPFieldFromXml or it's underlying function. If i create or change the Field in Classic or modern UI from single to multivalue it always changes the FieldType as well. So i felt this is a edge case originating in a missconfiguration that's why i closed it.