Reputation: 97
I'm using REST/JS calls to populate certain fields from a certain list item. I'm having troubles grabbing some of the fields as they are showing up as undefined when displaying results. I have noticed though, the fields that are showing up as undefined are type: Lookup, Person or Group, or Choice. Types that are showing up are Single line of text, Date and Time, and Number. I have looked through article after article but have not been able to figure it out. Here is a snip it of some of the code I'm talking about:
$(function() {
$.ajax({
url: "__URL__/_api/lists/getbytitle('Master%20Project%20List')/items?&$filter=Number eq '" + projectId + "'",
headers: {"Accept": "application/json;odata=verbose"},
type: "GET",
cache: false,
async: false,
}).success(function (data) {
$.each(data.d.results, function(key, value) {
//Project Title
console.log("TEST TITLE - " + value.Title);
Title = "*" + value.Title;
//Project Divison
console.log("TEST DIVISION - " + value.Div);
division = "*" + value.Div;
});
});
});
Here is a similar post: https://sharepoint.stackexchange.com/questions/147909/some-fields-undefined-when-display-results-from-rest-query
Upvotes: 1
Views: 2227
Reputation: 7059
You may need to explicitly request the desired field values using the $select
and $expand
options.
The $expand
option specificies which projected fields from a joined list are returned.
Consider the following excerpt from SharePoint 2013 - Understanding the SharePoint 2013 REST Interface by Jim Crowley and Ricky Kirkham:
When a SharePoint list has a lookup field to another list, this effectively serves as a join of the two lists. You can use the
$expand
option to return projected fields from the joined list. For example, if the Books list has aPublishedBy
field that looks up to theName
field of a Publisher list, you can return those names with this URL:_api/web/lists/getByTitle( 'Books')/items?$select=Title,PublishedBy/Name&$expand=PublishedBy
Notice that you reference the column in the foreign list by using the syntax
lookup_column_display_name/foreign_column_name
, notforeign_list_name/foreign_column_name
. It’s also important to note that you can’t select a lookup field name without also expanding it.
For more examples, see the answers given to this question on the SharePoint Stack Exchange site.
Upvotes: 1