2

I am trying to add a new list item into a sharepoint 2010 list using the client side object object in C#. I'm having an issue trying to set multiselect values.

I saw online to set the values in an array, so i did something like this in code.

Array arr = value.Split(new string[] { ", " }, StringSplitOptions.None); 
newItem["My MultiSelect Column Name"] = arr; 

//save changes 
newItem.Update();

//commit changes 
ctx.ExecuteQuery();

After I do the above I go to SharePoint and see that the row has the correct items in the array (delimited with ';'), but when I go in and edit that row, none of the items are actually checked.

Has anyone else run into this?

2 Answers 2

3

Multiple-Column Lookup value is represented as an array of FieldLookupValue objects.

How to get multiple Lookup field value:

var countryValues = item["Country"] as FieldLookupValue[];

How to set multiple Lookup field value:

var lookupVals = new[] { new FieldLookupValue { LookupId = 1 }, new FieldLookupValue { LookupId = 2} };
item["Country"] = lookupVals;
item.Update();
context.ExecuteQuery();
0

You can use following code, if you have Multiple Value LookUp Field and want to add listitem with all selected LookUp Field. Following code will add 3 lookUp Field value whose id is 1,2 and 3.

allBUValues=[1,2,3];

var lookupVals = [];

    for(i=0;i<allBUValues.length;i++)
    {
        var lookupVal = new SP.FieldLookupValue();
        lookupVal.set_lookupId(allBUValues[i]);
        lookupVals.push(lookupVal);
    }

    aListItem.set_item('BusinessUnit', lookupVals); 

    aListItem.update();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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