1

I seem to be struggling to set multiple values into SetFieldValueByValueCollection Method.

My code snippet below is:

var fieldToUpdate = list.Fields.GetByInternalNameOrTitle("Enterprise Keywords"); 
var taxKeywordField = context.CastTo<TaxonomyField>(fieldToUpdate);

string fieldvalue = "-1;#Test|dfb5ae8e-6271-4b27-86ea-0ff04a3292b0;-1;#TestAdditional|b9033830-9f74-4e1d-baaa-7711beeed141";
taxKeywordField.SetFieldValueByValueCollection(uploadFile.ListItemAllFields, new TaxonomyFieldValueCollection(context, fieldvalue, taxKeywordField));
taxKeywordField.Update();
uploadFile.ListItemAllFields.Update();

context.Load(uploadFile.ListItemAllFields);
context.ExecuteQueryRetry();

The error I recieve back is:

The given value for a taxonomy field was not formatted in the required < int > ; # < label >| format.

If I pass 1 parameter in -1;#Test|dfb5ae8e-6271-4b27-86ea-0ff04a3292b0 it works. I have tried varying the input string to -1;#Test|dfb5ae8e-6271-4b27-86ea-0ff04a3292b0;#TestAdditional|b9033830-9f74-4e1d-baaa-7711beeed141 and tried to run multiple updates on the field which overrides the field with the last term.

What am I doing wrong?

2
  • can you try with -1;#Test|dfb5ae8e-6271-4b27-86ea-0ff04a3292b0;#-1;#TestAdditional|b9033830-9f74-4e1d-baaa-7711beeed141 ? Jul 22, 2019 at 12:39
  • Thanks. 100% correct. Was missing the #. Just overlooked it, somehow, in all the examples.
    – Derrick
    Jul 22, 2019 at 12:54

1 Answer 1

1

Looks like you are setting the delimiter incorrectly.

The correct format is "<int>;#<label>|<guid> with ;# delimiter between the terms.

So modifying your string to

-1;#Test|dfb5ae8e-6271-4b27-86ea-0ff04a3292b0;#-1;#TestAdditional|b9033830-9f74-4e1d-baaa-7711beeed141 should work.

1
  • Thank you. Something so small I just kept on missing.
    – Derrick
    Jul 22, 2019 at 12:52

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.