14
Views
5
Comments
How to perform a search inside an aggregate
Application Type
Mobile

Hi,

I have created a calendar to display any bookings done for the month.

I have a Booking entity which holds any booking for a particular day and i want to display this on my calendar that got created.

On select of a particular Month, i have a client action that refresh the Booking aggregate based on the month that is selected. This aggregate will return 'n' rows where n being number of bookings in that month. Now, in the Calendar, on each day element, i have a container which displays a text "Booked slot" and its visibility is based on a condition which checks whether the refreshed aggregate contain booking for that date.

Now coming to my question :-), 

I need to perform a search query on the aggregate that is returned to check if a particular date is returned inside that aggregate.

Can someone help me how to achieve this please. 

mvp_badge
MVP
Rank: #177

Hello Siva,

You have a couple of options:

  • Add the filter to your Aggregate itself
    • You would add a Filter that goes against a local variable that would be blank initially, and the filter would be something like:
      SearchDate = NullDate() or Booking.BookingDate = SearchDate
  • Use ListFilter against the Aggregate results if you need both the original results as well as the filtered list
    • This is a client and server action, and it allows you to take a list, provide a filter (e.g. BookingDate = SearchDate), and returns back a new list of matching elements

Do one of those options help?

mvp_badge
MVP
Rank: #2

Alternatively, if you just need to check whether it's included, you can use ListAny instead of ListFilter.

Rank: #8626

I think the first one wont work, as i am searching on a month basis and not on day basis, so I will get a list of records for the entire month and i need to search it through each day.

I was trying the second option right now and i think this might work. I am going to put a for each on the client action to iterate around the refreshed aggregate and search for each day and return a boolean response to identify whether there is a booking or not for that date.

Thanks for the prompt response. Appreciate that :-)


Rank: #8626

can you give me an example how to use ListAny and where to put it? like can i use this in client action if condition?

mvp_badge
MVP
Rank: #2

Hi Siva,

ListAny is not a function, so it cannot be used in an If. However, ListAny is much faster than ListFilter, as it can stop at the first occurence, and doesn't need to create another List. So if you only need to know whether an element is present or not, ListAny is better than ListFilter.