pnpcore icon indicating copy to clipboard operation
pnpcore copied to clipboard

Taxonomy Value handling relies on FieldType instead of AllowMultipleValues

Open czullu opened this issue 1 year ago • 4 comments

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

  1. Create a List with Field of Type TaxonomyFieldType and then turn multivalue support on after wards.
  2. Add Select multiple Values from Taxonomy Store
  3. Try to Read Values with pnpcore - you will get no values
  4. 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

czullu avatar Feb 16 '24 07:02 czullu

It seems that the current modern UI does actually change the FieldType according to the setting of AllowMultipleValues.

czullu avatar Feb 16 '24 07:02 czullu

@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 avatar Feb 16 '24 13:02 czullu

@czullu : can you provide context on how this is handled in PnP Framework, will save some time for a possible fix

jansenbe avatar Feb 19 '24 08:02 jansenbe

@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 avatar Feb 19 '24 11:02 czullu

@czullu : why was this closed again? I did not yet had to change to work on it, is this not needed anymore?

jansenbe avatar Mar 12 '24 08:03 jansenbe

@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.

czullu avatar Mar 12 '24 09:03 czullu