0
votes

I'm creating an import script to update my items in Sitecore using data from a spreadsheet. Several of the fields are multilists. The data for in the spreadsheet that is supposed to be entered into the multilist might be "red, blue, green," for example. How do I edit the value of the multilist field?

3

3 Answers

4
votes

I assume that you already have items in Sitecore which are called as your colors. You need to find their IDs and set them as the value of your field separated with | character, e.g. {some-guid}|{another-guid}|{and-one-more-guid}.

Item redColorItem;
Item blueColorItem;
Item greenColorItem;

Item importedItem;
importedItem["Colors"] = redColorItem.ID + "|" + blueColorItem.ID + "|" + greenColorItem.ID
4
votes

I’d like to extend previous answers. There is API to work with multi list fields in Sitecore, you should consider it, instead of manual generation of pipe-separated strings value. Something like:

  using (new EditContext(item))
            {
                MultilistField mlField = new MultilistField(item.Fields["Multilist"]);
                mlField.Add(redColorItem.ID.ToString());
                mlField.Add(blueColorItem.ID.ToString());
                mlField.Add(greenColorItem.ID.ToString());
            }
0
votes

You can understand what should be put to field when switch on "Raw values" in Content Editor.

Multilist field contains IDs of other items with "|" separator. It means that you should create red, blue and green items as your dictionary. And then convert you "red, blue, green" to {id of green item}|{id of blue item}|{id of green item.}