- How to make a REST call in SharePoint App and SharePoint Provider Hosted App – Part 1
- SharePoint 2013 List Operations in REST– Retrieve List Fields Basics – Part 2
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 LooukUp */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 LooukUp 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);
Comments