4

I have a field called customerType in the Metadata of a Schema. It is a multi-valued text field. I would like to update the Component using Event System to set the Metadata of this field. So far I am able to place single value into this field using the code snippet placed below.

    foreach (ItemField field in metadataFields)
    {
       if (field.Name.Equals("customerType"))
       {     
           ((TextField)field).Value = "Test1";
       }
    }

Could you please let us know how to place multiple values in this multi valued text field. For instance, I would like to have "Test1" and "Test2" into this field.

1 Answer 1

5

You should use .Values property instead of .Value .Values property is always available if field is multi-value.

You can have something like this:

         foreach (ItemField field in metadataFields)
                {
                    if (field.Name.Equals("customerType"))
                    {
                        IList<string> values = ((TextField)field).Values;
                        foreach (string value in values)
                        {
                            //do something
                        }

                    }
                }

You can also see it in TOM.NET API:

enter image description here

3
  • Thanks Marko. The Values property seems to be read-only, so it may not be helpful in setting up a value in textbox corresponding to that field.
    – Habeeb
    Mar 26, 2018 at 11:16
  • 1
    Values is indeed read only, but you can add or remove items from this collection, so you can do something like field.Values.Add("data"); Mar 26, 2018 at 14:32
  • Yes, @Harald is correct.
    – Marko Milic
    Mar 26, 2018 at 15:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.