Filter with multiples inputs (selected or not)
Question

Hello Community!

I have the following difficulty:

there is an input on the screen that can be filled in or not, if it is chosen I want to filter this field in the table, if it is not filled out the search in this attribute would be without a filter. The point is that I would like to do this same logic for several inputs (combo box, check box, date picker) and they must be with the && (AND) logic. That is, only  fields that are chosen on the screen must be part of the filter.

 I thought about doing this with the aggregate, comparing the selected data of the variable with the attributes of the entity. Because what I already did with a filter in OutSystems considered that all fields would be selected, my doubt consists in the fact that this field may or may not be selected ... But I am having difficulties in this part. Is there any way to do this dynamically in OutSystems?


I read these links, but I didn't find the answer:

https://www.outsystems.com/forums/discussion/23117/strange-aggregate-filter/

https://www.outsystems.com/forums/discussion/51195/if-statement-in-aggregate-filter/

https://success.outsystems.com/Documentation/11/Developing_an_Application/Use_Data/Query_Data/Filter_Query_Results?origin=d

I made a sample example from screen. (attached oml)


Best Regards, 

Jessica Marques. 

SampleTests.oml

mvp_badge
MVP
Solution

Hi Jessica,

See attached OML. I made some assumptions of what attributes from the entities you wanted to filter on.

Also the From and To Date you have the correctly mapped the widgets to the inputs From widget was connected to the Search.ToDate and the Date To widget tot the Search.FromDate. 

That took me some minutes to figure out why my filter was not working initially.

Regards,

Daniel

SampleTests.oml

Hello Daniël Kuhlmann

Thank you very much for your kindness in presenting the code in the sample test. The way you did it simplified a lot, I had made some attempts with "if" and it hadn't worked out very well. My mistake in this analysis was not to use the sample data entities that had any connection, because I wanted to do this exercise of filtering data from two different entities ... I'm going to do this experiment now ...

Thanks again for the help.

Best Regards, 

Jessica Marques. 

mvp_badge
MVP

Hi Jessica,

For the mentioned requirment, you can use the Aggregate for getting the filered data. 


As per the requirment, the filter conditions can be divided/understood in two points

  1. Some filter value could be "may or may not be selected" --> OR
  2. Even though point 1 is to be considered, still all the filter parameters must be included in the filter condition --> AND


Filter Condition

(Search.EmployeeId = NullIdentifier() or Sample_Employee.Id = Search.EmployeeId) 
and 
(Search.DepartmentId = NullIdentifier() or Sample_Employee.Department = Search.DepartmentId)

And

(Search.DateFrom = NullDate() or (Search.DateFrom <= Sample_Employee.HiringDate))
 and 
(Search.DateTo = NullDate() or (Search.DateTo >= Sample_Employee.HiringDate))


Hope this helps you!


Kind regards,

Benjith Sam

SampleTests.oml

Hi Benjith Sam,

That was another question that I had and I think you solved it. When I do, for example, Filter 1 and filter 2 (As you did) This already represents in logic that the condition of the two filters will be AND. Right?

This community is really amazing, thanks so much for your kindness in explaining the filter example in my own sample data. This help me a lot to understand the abstraction of what needs to be done.

Thanks for your explanation. 

Kind Regards, 

Jessica Marques. 

mvp_badge
MVP

You're welcome, Jessica :)


When I do, for example, Filter 1 and filter 2 (As you did) This already represents in logic that the condition of the two filters will be AND. Right?

Yes, you are absolutely correct. When defining two filter conditions seperately in the Aggregate filter section the AND operator is applicable in-between Filter1 and Filter2 condition.


I'm glad that we could able to help you :)


Kind regards,

Benjith Sam

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.