How to fetch data from a look up field of SharePoint List using REST API in jquery?
Fetch data from a look up field of SharePoint List using REST API:
Using below code we are able to fetch data from the lookup field.Events//SharePoint list Name
Program is Lookup field, Its internal name is Program in Events list.
Program is lookup from another field of another list where its internal name Title.
To fetch the data from look up field we need to add Program/Title in $select and $expand
var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('Events')/items?$select=*,Program/Title&$expand=Program/Title";//replace list Name (Events) and try in the console of browser
$.ajax({
url:url,
method:"GET",
headers: { "accept": "application/json;odata=verbose", //It defines the Data format
"content-type": "application/json;odata=verbose" //It defines the content type as JSON
},
success:function(response){
console.log(response);
response.d.results.forEach(function(d,key){
console.log(d);
});;
},
error:function(error){
console.log(JSON.stringify(error));
}
});
Output:
In console of browser it will look like.
If we expand it then we will able to get data item as json array or array of object.
Comments
Post a Comment