1

I am trying to get data from Sharepoint custom list in group by using REST API.

I am trying to achieve this in Mobile Application so jquery solution not supported for me.

I just want to get data as clients name wise from my custom list.

There Are Many other entries in list for same clients and i just want all client data just one time not each record of all clients one record for each client.

How can i achieve this any alternate solution is there then please suggest.

Any Help Highly Appreciated.

3 Answers 3

1

You can use CAML query with REST Service API as mentioned here Using CAML with SharePoint API.

You can build CAML GROUP BY statement and then get executed by REST Service API call.

1

I don't think Group By is supported in REST API. Below are alternatives to achieve this. You need to apply Group By once data is returned from REST service.

Assuming this is your getting list items via SharePoint REST API:

function getListItemsByQuery(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);
        }
    });
}

Below function can be used to get unique values

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

Use above functions like below

getListItemsByQuery('https://example.com/project','MyList','?select=Title',
    function(items){    
       var ItemsafterGroup = FilterValuetoGroupBy(items,'Title');
       console.log(ItemsafterGroup );
    },
    function(error){
       console.log(JSON.stringify(error));
    }
);
0

Try using this API :

/_api/Web/Lists/GetByTitle('List Name')/Items?$filter=Column_Name eq 'NameOfTheClient'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.