SharePoint 2013 List Operations in REST – Retrieve List Fields Basics

You can use the function specified in the first post to call the REST URLs. You can use the appropriate function depending on the App type you are developing.

Get selected fields in SharePoint List using SELECT REST operation.

Getting single value fields

/*
 List Name : listname
 Columns: Title => Text , ID =>  Number
*/
 
var url = "/_api/web/lists/getbytitle('listname')/items?$select=Title,ID";
 
function s(data){
 
    // get the data and convert to JSON Objects
    var d = JSON.parse(data.body).d.results[0]; 
    
    alert(d.ID);
    alert(d.Title);
    
}
 
function f(data){
    alert(data);
}
 
getREST(url,s,f);

Getting single value Lookup fields

/*
 List Name : listname
 Columns: ID =>  Number , CountryLookup => List LookUp 
*/
 
var url = "/_api/web/lists/getbytitle('listname')/items?$select=ID,CountryLookupId";
 
function s(data){
 
    // get the data and convert to JSON Objects
    var d = JSON.parse(data.body).d.results[0]; 
    
    alert(d.ID);
    
    // 3 , will return the ID 
    alert(d.CountryLookupId);
}
 
function f(data){
    alert(data);
}
 
getREST(url,s,f);

Getting multiple value Lookup fields

/*
 List Name : listname
 Columns: ID =>  Number , CountryLookup => List LookUp multiple
*/
 
var url = "/_api/web/lists/getbytitle('listname')/items?$select=ID,CountryMultiLookupId";
 
function s(data){
 
    // get the data and convert to JSON Objects
    var d = JSON.parse(data.body).d.results[0]; 
    
    alert(d.ID);
    
    // [3,5]
    var mul = data.CountryMultiLookupId.results; 
    // iterate and show the results, $.each is a jQuery function
    $.each(mul,function(i,ele){ alert(ele) });    
}
 
function f(data){
    alert(data);
}
 
getREST(url,s,f);