0

I've been working with a jQuery AJAX call to post data to one of my SharePoint lists.

One of the fields in this list is a look-up field. In forming my JSON data to push to the list I was able to push data to each field with the exception of the look-up field.

How do I push data into a lookup field?

I know I need to push the target list's ID to the look-up field, but have gotten hung up on just how to format the data.

  • With search engines and within StackExhange, I've found many partial answers. Here I hope to build ready reference for the future. – EFH Jan 16 '15 at 15:21
0

Here is an example from this question:Updating Lookup Values with the REST API

var call = jQuery.ajax({
        url: _spPageContextInfo.webAbsoluteUrl +
            "/_api/Web/Lists/getByTitle('Sales Opportunities')/Items(5)",
        type: "POST",
        data: JSON.stringify({
            "__metadata": { type: "SP.Data.Sales_x0020_OpportunitiesListItem" },
            StateId: 2
        }),
        headers: {
            Accept: "application/json;odata=verbose",
            "Content-Type": "application/json;odata=verbose",
            "X-RequestDigest": jQuery("#__REQUESTDIGEST").val(),
            "IF-MATCH": item.__metadata.etag,
            "X-Http-Method": "PATCH"
        }
    });
  • 1
    Then second answer for that post summarizes what I found well. I will upvote it. Thank you for the link. I'll use 'updating' in my future searches along these lines. That seems to be the key to finding this result in the search bar. The key is the single value vs multiple value and the 'results' array. – EFH Jan 16 '15 at 15:35
  • Appending 'Id' to the lookupfieldname is essential as well. It seems to have been missed in the above referenced answer, but having paid a bounty, I've not the reputation to comment. – EFH Jan 16 '15 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.