Visual Builder

Get Involved. Join the Conversation.

Topic

    Hugo Zandt
    Filter on unique results
    Topic posted September 17, 2019 by Hugo ZandtGreen Ribbon: 100+ Points, tagged Business Objects 
    25 Views, 2 Comments
    Title:
    Filter on unique results
    Summary:
    Is it possible to get unique items from an SDP or rest call response?
    Content:

    Hello community,

    Is it possible to get unique items from an SDP or rest call response?

    An example to clarify using a car app. Our dataset includes a ‘car’ business object which contains brand, model and color.

    We want to answer the question “which brands produce yellow cars?”

    If we apply a filter on an SDP where we filter on the attribute color being equal to “yellow” we get an output that contains some brands multiple times because they have several models in that color. How can we best prevent that?

    Thanks,

    Hugo

    Version:
    19.1.3
    Image:

    Comment

     

    • Duncan Mills

      This is a case where you really need to have a specialised endpoint that encapsulates this functionality - as you will know it's super simple to do this kind of filtering at the database level and in an ideal world you'd have a endpoint based on a view that applied the uniqueness (or grouping) overlay at the SQL level and then your REST calls into that endpoint can be simple. 

      So this is a case for having the data in a full Oracle database where you have the ability to add views and custom endpoints rather than just using the built-in business objects. 

      • Hugo Zandt

        Thanks for the clarification.

        A database with custom endpoints would be an ideal solution, but for now we’ve build a workaround using business objects, for the example it would look like this:

        We’ve defined ‘brand’ in a separate business object and each car references a brand. When we apply the filter ‘color equals yellow’ to cars we use the response to build an array of filters with the brand ID’s of the cars. We apply this array of filters to brand to get the final response with unique brands we’re after.

        A filter for the brands would look like this:

        {

        "attribute": "id",

          "op": "$eq",

          "value": "1"

         }

        {

          "attribute": "id",

          "op": "$eq",

          "value": "2"

         },

         {

          "attribute": "id",

          "op": "$eq",

          "value": "2"

         }

        Combined with “op”:”$or”

         

        It’s not the prettiest solution but it works for the being.