1

I'm having trouble setting multi lookup field. I found this example:
Update a LookupMulti Column value in SharePoint using Client Object Model C# and Setting a SharePoint Multi-value Lookup Field value using PowerShell and CSOM

And also this: Add values to lookupmulti field in c#, but its not using CSOM.

The code I have is this:

                ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
                SP.ListItem oListItem = oList.AddItem(itemCreateInfo);

                FieldLookupValue[] arr = new FieldLookupValue[1];
                FieldLookupValue lvItem = new FieldLookupValue();
                lvItem.LookupId = 7;
                arr[0] = lvItem;

                oListItem["prjIBusers"] = arr;

                oListItem.Update();

                context.ExecuteQuery();

But it throws the following error at ExecuteQuery()

  Microsoft.SharePoint.Client.ServerException
  HResult=0x80131500
  Message=Unknown Error
  Source=Microsoft.SharePoint.Client.Runtime
  StackTrace:
   at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream)
   at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse()
   at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb)
   at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()

1 Answer 1

2

Try this code:

var lookupValues = new ArrayList();            
var lookupValue = new FieldLookupValue { LookupId = 7 };
lookupValues.Add(lookupValue);
//var lookupValue1 = new FieldLookupValue { LookupId = 5 };
//lookupValues.Add(lookupValue1);
oListItem["prjIBusers"] = lookupValues.ToArray();
oListItem.Update();
context.ExecuteQuery();

OR:

Don't build an array of SP.FieldLookupValue, instead save multiple lookup values to string as mentioned here:

SharePoint 2013: How to update multi-value lookup field using JavaScript CSOM.

3
  • If that doesn't work then try using this. Commented May 14, 2020 at 12:46
  • This did not work, same error, but using a string value did, ty, could you please modify the answer so I could accept it
    – Idra
    Commented May 14, 2020 at 13:23
  • Glad it worked for you. I have updated my answer. Commented May 14, 2020 at 13:29

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.