Unable to update taxonomy field in ItemAdded event
-
09-12-2019 - |
Question
My code worked fine with my previously built (using SP web GUI) custom document library, whereby I would add a document and on the pop-up with the field textboxes, my ItemAdded event would set a taxonomy field from the an item in the termstore.
However, after changing my setup to a one where I programmatically create the content type and fields, the code to set the taxonomy field no longer works.
The SetFieldValue in the following snippet gives an error: "ArgumentOutOfRangeException - The SPListItem being updated was not retrieved with all taxonomy fields"
var listTerms = new List<Term>();
listTerms.Add(tagTerm);
field.SetFieldValue(properties.ListItem, listTerms);
properties.ListItem.SystemUpdate();
I have checked my elements and schema files and the particular field in question is set to TaxonomyFieldTypeMulti and Mult="TRUE".
When I browse the column via SP Web GUI, it has the "AllowMultipleValues" checked.
UPDATE
So the latest error I get is associated with a missing notefield (as far as I could Google!).
So I tried the following: http://sharepointificate.blogspot.ca/2012/04/deploying-multi-select-managed-metadata.html
I modified my schema and element files by adding the notes field for the target MM field and also added the code to attach note id on feature event.
But still I get the same error.
ANOTHER UPDATE
I am using a custom Edit Form for this document library and so maybe I am missing some special markup for the hidden notefield???
Not sure what else to check so any help appreciated.
thanks,
KS
Solution
Ok, the issue was that I did indeed need to add the note fields and also all fields MUST have a name and displayname attribute. This must be done in the elements and the schema files.