This project has moved and is read-only. For the latest updates, please go here.

Obtaining the value of a Look Up column

May 15, 2013 at 3:58 PM
Edited May 15, 2013 at 4:01 PM
I have the following scenario. I have a form where the text fields and radio buttons are blank. I’m using SPServices to collect the values entered (in a text field) or selected (through a radio button) to either update or create a new list item.

At the moment, the only two columns that aren’t updating both happen to be lookup columns. With my example below, i’m trying to update the “Person” column with the text that has been entered into the person container (which is using jquery UI to provide an autocomplete on person names from a list)
["Person", $('#person-container').val()],
I’m having the same problem with a lookup radio button:
["Partner", $('input:radio[name=eop]:checked’, ‘.partner-wrapper’).val()]
Here's my full code which is wrapped in a function.
        operation: "UpdateListItems",
        async: true,
        batchCmd: "New",
        listName: "People",
        valuepairs: [
            ["Person", $('#person-container').val()],
            ["Partner", $('input:radio[name=eop]:checked’, ‘.partner-wrapper’).val()]
        completefunc: function (xData, Status) {
            alert('Thank you');
Marc kindly suggested the following ["Person", "0;" + $('#person-container').val()]. However this unfortunately didn't work.

Any information regarding the above would be greatly appreciated.
May 15, 2013 at 4:17 PM
And I had a typo in what I suggested!

["Person", "0;#" + $('#person-container').val()]
May 15, 2013 at 4:26 PM
Edited May 15, 2013 at 4:26 PM
Thanks for the rapid response Marc!

Unfortunately, no luck there either. I included the "alert(xData.responseText)" to see if i could capture further information.

The person filed produces this information within the alert.


Again, thanks for your time.
May 16, 2013 at 11:40 AM

My apologies, great suggestion. Misunderstood from my end. You're right, getting the ID is absolutely key, and actually using just the ID alone works perfectly well.

A content query web part pulled through the people and their IDs.
A variable was created to look at the people container where the title matched on the value entered into the text field and pull through the ID attribute. This variable was then used to populate the value field.

An additional thanks to front end guru Leigh Docking.
var peopleID = $('.people[title="' + $('#person-wrapper').val() + '"]').attr('sharepointid'); 

    operation: "UpdateListItems", 
    ID: userInformation.listitemid, 
    async: true, 
    batchCmd: "Update", 
    listName: "People", 
    valuepairs: [   
        ["People", peopleID],
May 16, 2013 at 12:17 PM
Glad you got it working!