0

I've multiple folders inside the pages library enter image description here

Within each folder I have pages enter image description here

Grupo de produtos is of type taxonomy. I run the function GetPagesProd and for each item I get the value from Grupo de produtos, is it possible to get all the values from that column without searching one by one and cut the duplicate ones?

function GetPagesProd(FirstFolderProd, FirstFolderWithoutSpaceProd, GetTagFolder, valuri, SearchURIPagesFilesWS, PageTag){
        jQuery.ajax({
            url: SearchURIPagesFilesWS + "?$select=ListItemAllFields&$expand=ListItemAllFields",
            type: "GET",
            headers: {
                "accept": "application/json;odata=verbose",
                "content-type": "application/json;odata=verbose",
            },

            success: function (data) {
                var dataresult = data.d.results;
                dataresult = [].slice.call(dataresult);
                dataresult.forEach(function (key, value) {
                    var TagIndividualPage = (key.ListItemAllFields.Intranet_SubCategoria.results["0"].Label);

                    console.log(TagIndividualPage);
                });
            },
            error: function (error) {
                console.log(error);
            }
        });
    }
3

While Joe McShea is correct in that there is no direct "distinct" type of operation through the REST API, as I learned in the answer I accepted to a question I had over on S.O., you can get distinct values through some clever querying.

Now, I'm not sure you can do this directly using oData query options (although you might be able to), you could certainly do it through CAML queries as in my accepted answer from S.O., and you can use CAML queries through the REST API by hitting the _api/web/lists/getbytitle('list name')/getitems endpoint.

The basic idea behind the technique is this:

  • Make your query orderby the field you are trying to get distinct values of.
  • For the first query, select $top=1 (or in CAML, row limit of one).
  • Save that value as the first of your distinct values.
  • Query again, still with orderby on the field , but also apply a filter that will only return items where the field value is greater than the value you just got.
  • Again only take $top=1 or row limit of one.
  • Save that value.
  • Repeat, using the second value as the greater than filter value.
  • Keep repeating using the last retrieved value as the greater than filter value, until you get a result set of none. At that point you should have all the distinct values for that field.
  • That is a clever solution. To be fair, under most circumstances, it would be less code and much better performance to get all results and post-process them to a distinct list, but this will clearly get the job done. – Joe McShea Mar 27 at 12:56
  • @JoeMcShea actually, in the situation I was in when I posed my other question over on S.O., I was querying a list that had around 4k items, and it was certainly possible that the list would grow to over 5k items, so doing it this way was also a way to get around the list view threshold. In theory, yes, querying for everything and then post-processing is less code, but in some situations that may not be possible. – Dylan Cristy Mar 27 at 13:26
  • Fair enough, that's why I said under MOST circumstances, but list view threshold is the obvious exception, and any case where there are a lot of results and relatively few distinct values could make sense. – Joe McShea Mar 28 at 1:02
2

No, SharePoint REST/OData has no equivalent select distinct. You can only achieve this by post-processing.

Ref: How to get distinct values using Rest Api and bind to html dropdown

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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