1

I have created a custom drop-down list and inserting drop-down data into lookup column(in a list).

How to insert drop down data into a look up column?

I am trying below code but it is not working.

oListItem.set_item('SupportCategoryName', ddlgrpname);

3 Answers 3

1

Please try following code. It is perfectly working code. Here "valToBeInsertd" is varible name.

function InsertIntoLookUp()
{

    var itemCreationInfo = new SP.ListItemCreationInformation();
    oListItem = list.addItem(itemCreationInfo);

    var selectedText = valToBeInsertd;


    oListItem.set_item('Name', "-1;#" + selectedText); 
    oListItem.update();  
    context2.load(oListItem); 
    context2.executeQueryAsync(SuccessInsertIntoLookUp, FailInsertIntoLookUp); 
}
function SuccessInsertIntoLookUp()
{
    alert("inserted....");
}
function FailInsertIntoLookUp()
{
    alert("failed to insert into lookup");      
}
0

Use SP.FieldLookupValue

  var lookupSingle = new SP.FieldLookupValue();  
  lookupSingle.set_lookupId(theIdHere);  
  oListItem.set_item('SupportCategoryName', lookupSingle); 
0
var e = document.getElementById('<%=ddlgrpname.ClientID%>');
var ddlgrpname = e.options[e.selectedIndex].value;
oListItem.set_item('SupportCategory', ddlgrpname);
1
  • Along with code, can you please add some description of it.
    – Asad Refai
    Commented Oct 13, 2015 at 11:09

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.