Search code examples
sharepointoffice365spservices

How to add values to multiple lookup field in SharePoint using UpdateListItems


I need to add multiple values (ID fields of another custom list) to a Multiple Lookup field using Sp-services.
What is the correct format of the data to be used ?
I have tried like ( 5,9,6 ) but only selecting the first item.


Solution

  • I have found a way to do it.

    // "list1Id" contains the array of LIST1 ID fields that you want to add...
    // "MULTIPLELOOKUPFIELD" is the multiple lookup field in the LIST2...
    
    var multipleLookupValue ="";
    for(i = 0; i < list1Id.length ; i++)
    {
        multipleLookupValue = multipleLookupValue + list1Id[i]+";#data;#";
    }
    
    var method = "UpdateListItems";
    
    $().SPServices({
        operation: method,
            async: false,  
            batchCmd: "New",
            listName: "LIST2" ,
            valuepairs: [["MULTIPLELOOKUPFIELD",multipleLookupValue]],
                completefunc: function (xData, Status) { 
    
                    //alert("Added new item to LIST2 list");                                            
                }
    
    });
    

    May be it will help someone...