Domanda

I am using the following function to retrieve data from a list using the SP REST API. All seems to work except for the 'Created By' field. How do can I retrieve data from the 'Created By' field. I get 'undefined' for the 'Created By' field. Thank you.

function($scope, $http) {
    $http({
        method: 'GET',
        url: "https://.../_api/web/lists/GetByTitle('NET%20Support%20Tracker')/items?$top=1000",
        headers: {"Accept": "application/json;odata=verbose"}
    }).then(function (data, status, headers, config) {
        const items = data.data.d.results;
        console.log(items);
        console.log('Title: ' + items[0].Title);
        console.log('Issue: ' + items[0].Issue);
        console.log('Created by: ' + items[0]['Created By']);

}, function errorCallback(response) {
    console.log(response);
});

});

È stato utile?

Soluzione

You have to expand the user fields while retrieving form SharePoint list items you API should have $select=Author/Name&$expand=Author Author is internal name of Created By field.

Note: When you use expand it is mandatory that you specify fields that you want to retrieve in $select

Altri suggerimenti

You have to use the internal name author. Because it is a person field you also have to expand it. See this link list all expandable properties. You can get the internal field name by using the following command _api/web/Lists/GetByTitle('<directory name>')/fields?$filter=Title eq 'Your Field'. I would also recommend to always use select to define the fields you want to return. Your call should be something like this https://.../_api/web/lists/GetByTitle('NET%20Support%20Tracker')/items?$top=1000&$select=Title,Issue,Author/Name&$expand=Author

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top