Sharepoint - SharePoint 2013 REST display lookup fields?
In order to select User
or Lookup
field values the $expand operator is used (for making a projection of AnnouncedBy
column with User Information List
).
For example, the following query
https://contoso.sharepoint.com/news/_api/web/lists/getByTitle('Announcements')/items?$select=*,AnnouncedBy/Title&$expand=AnnouncedBy
will return the following result:
Complete example
The example demonstrates how to bind User field value in AngularJs:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular-sanitize.js"></script>
<script>
var app = angular.module('AnnouncementsList', ['ngSanitize']);
app.controller('ListController', function ($scope, $http) {
$http({
method: 'GET',
url: "https://contoso.sharepoint.com/_api/web/lists/getByTitle('Announcements')/items?$select=*,AnnouncedBy/Title&$expand=AnnouncedBy",
headers: { "Accept": "application/json;odata=verbose" }
}).success(function (data, status, headers, config) {
$scope.items = data.d.results;
}).error(function (data, status, headers, config) {
//error handling goes here..
});
});
</script>
<h1>Announcements</h1>
<div ng-app="AnnouncementsList">
<ul ng-controller="ListController">
<li ng-repeat="item in items">
<span>{{item.Title}}</span> By <span>{{item.AnnouncedBy.Title}}</span>
</li>
</ul>
</div>
Result
Try adding following in the URL
$select=AnnouncedBy/Id,AnnouncedBy/Title,*&$expand=AnnouncedBy
Reference:
SharePoint 2013–retrieving the lookup value of User fields using the REST API
Getting User Information with the SharePoint 2013 REST API