0

I have a CheckBoxList in which there is a Lookup values. Now I need the selected values and update it to the Lookup column in the list using SPServices. I tried the below code:

var selectedValues = [];
 $("[id*=chbxPAD] input:checked").each(function () {
        selectedValues.push($(this).next().html());
    });
 $().SPServices({
    operation: "UpdateListItems",
    listName: "Requirements",
    ID: id,
    valuepairs: [
                 ["Request_x0020_Type", selectedValues]
                ],

    completefunc: function (xData, Status) {
        alert("Updated.");
        }
   });
2
  • If you do alert(selectedValues); what values are coming up? Commented May 28, 2015 at 13:13
  • only the selected text like if there is a value in CheckBoxList like "Test1, Test2, Test3" and if I have selected Test1 and Test2, then selectedValues = "Test1,Test2"
    – DRS
    Commented May 28, 2015 at 13:18

2 Answers 2

0

SharePoint lookup consist of 2 parts: ID of the item in the list and the Value. You can't set lookup only by the value because they are not the unique and can be the same with another item in this list. You should specify ID of the selected element.

3
  • Thanks. I have done the same thing as you told. But still column doesnt gets updated
    – DRS
    Commented May 28, 2015 at 13:47
  • As I understand you try to update multi lookup column? If so, the format should be like: "ID_1;#Value_1;#ID_2;#Value_2". In your case, try to specify something like this: valuepairs: [["Request_x0020_Type", "1;#Test1;#2;#Test2"]], Commented May 28, 2015 at 14:09
  • Thanks.. :) Its working.
    – DRS
    Commented May 29, 2015 at 4:43
0

Lookup Column needs to be treated differently.

The value pair should be like

valuepairs: [
             ["Request_x0020_Type", ["1;#Test1","2;#Test2"]]
            ],

Where 1 & 2 are corresponding ID values of Test1 and Test2.

1
  • var selectedValues=''; $("[id*=chbxPAD] input:checked").each(function () { selectedValues+= $(this).val()+";#"+$(this).next().html()+","; }); var chbPADValue = selectedValues.slice(0, -1); alert(chbPADValue); I am getting value as 1;#Test1,2;#Test2 and then i am updating chbPADValue but still column doesnt get updating
    – DRS
    Commented May 28, 2015 at 13:40

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.