Make a filter for a record list with combo Box - How to make the default "All" Value

Hello community!

I'm trying to build a Filter for my search with a combobox (dropdown) to pick a category.
So I associate the record list to the aggregate and I've created the local variable with type Identifier so I can keep the picked value from the combobox. 

I've also added a special value for the "All" option in case users don't want to apply this filter, this "All" option is valued as 0.

I'm having a hard time figuring out how to apply the filter, because if I set in the filter category.Id = Variable, when people pick the "All" option, instead of returning all records it won't return any cause there's no record with id = 0.


Solution

Hi, try this:

Variable = NullIdentifier() or category.Id = Variable,

Solution

João Melo wrote:

Hi, try this:

Variable = NullIdentifier() or category.Id = Variable,

Hey João,
Thanks for the repply.

I've tried as you said but can't make it work. In the Aggregate I set the filter "Category.ID = CatVariable", this CatVariable is a local variable of the type category Identififer.


The On change action I've put an IF (CatVariable = IntegerToIdentifier(0)), when true it Assigns CatVariable = NullIdentifier() and goes to the Aggregate Refresh, if false it just does the Aggregate Refresh.

When I pick the special combobox option "All" which sets the value to "0", the aggregate doesn't return any records. Am I doing something wrong?

I haven't assign a Special Variable, I assume this way the Special List Option will use the variable that the combobox is using right? Or if I have a specialList value I'll always have to use a special variable different then the combobox one ?

João Melo wrote:

Hi, try this:

Variable = NullIdentifier() or category.Id = Variable,

Hey João! Sorry, I got it! The filter has to be as you said "Variable = NullIdentifier() or category.Id = Variable"

I thought you were telling me I shoud use one way or the other.

It worked as you said! Thank you!


Hi Frederico.

You don't need the IF or to check anything in the OnChange logic. You just need to add what I said directly in the Condition of your Aggregate:

CatVariable = NullIdentifier() or Category.ID = CatVariable

This condition, when evaluated by the DB will be interpreted as: If CatVariable is Null, then ignore the second statement (Category.ID = CatVariable), don't filter anything and bring all the records.


PS: Comparing a variable with IntegerToIdentifier(0) is not a good practice. Better comparing the variable with NullIdentifier(), which is the same thing but at least you don't have hard-coding.

João Melo wrote:

Hi Frederico.

You don't need the IF or to check anything in the OnChange logic. You just need to add what I said directly in the Condition of your Aggregate:

CatVariable = NullIdentifier() or Category.ID = CatVariable

This condition, when evaluated by the DB will be interpreted as: If CatVariable is Null, then ignore the second statement (Category.ID = CatVariable), don't filter anything and bring all the records.


PS: Comparing a variable with IntegerToIdentifier(0) is not a good practice. Better comparing the variable with NullIdentifier(), which is the same thing but at least you don't have hard-coding.


You'r right. I misunderstood your first comment. thank you! It's working!