Retrieve individual data from a SharePoint list using the REST API

How to get individual data of SharePoint list columns using REST API? Is there a way to achieve this without a loop?

Thank!

+3


source to share


2 answers


According to Use OData query operations in SharePoint REST requests , such an operation is grouping

not supported.

The solution is to apply the grouping after the JSON results are returned from the SharePoint REST service.

How to get different values ​​from an array using jQuery

function groupBy(items,propertyName)
{
    var result = [];
    $.each(items, function(index, item) {
       if ($.inArray(item[propertyName], result)==-1) {
          result.push(item[propertyName]);
       }
    });
    return result;
}


var catalog = { products: [
   { category: "Food & Dining"},
   { category: "Techonology"},
   { category: "Retail & Apparel"},
   { category: "Retail & Apparel"}
]};

var categoryNames = groupBy(catalog.products, 'category'); //get distinct categories
console.log(categoryNames);

      

JSFiddle



Example

Let's assume the following function is used to retrieve list items via the SharePoint REST API:

function getListItems(url, listname, query, complete, failure) {
    $.ajax({
        url: url + "/_api/web/lists/getbytitle('" + listname + "')/items" + query,
        method: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        success: function (data) {
            complete(data.d); 
        },
        error: function (data) {
            failure(data);
        }
    });
}

      

Then, the following example shows how to print individual task names:

getListItems('https://tenant.sharepoint.com/project','Tasks','?select=Title',
    function(items){    
       var taskNames = groupBy(items,'Title');
       console.log(taskNames);
    },
    function(error){
       console.log(JSON.stringify(error));
    }
);

      

+5


source


From what I understand you are talking about http: ///_vti_bin/Lists.asmx.

Well yes, you should be able to query data through plain SQL - select Distinct ...



I am using the same concept for the Users web service. However, it is easy for you.

link: http://msdn.microsoft.com/en-us/library/office/ms429658(v=office.14).aspx

0


source







All Articles