Hello!
I'm facing an issue in OutSystems where I need to create an attribute or filter for even or odd IDs in an aggregator. I have a list of items with unique IDs, and I want to filter them based on whether the ID is even or odd.
I've tried using standard filters and attributes, but I couldn't find a straightforward way to achieve this. Can someone please guide me on how to create an attribute or filter that can help me achieve this in OutSystems?
Any help or insights would be greatly appreciated. Thank you!
Just to offer a 'calculate it yourself, so you can still use an aggregate' alternative,
add this calculated attribute, a boolean named IsEven
DecimalToInteger(IdentifierToInteger(Entity.Id) / 2) * 2 = IdentifierToInteger(Entity.Id)
Dorine
Dorine, thank you so much, this is not the first time you’ve helped out! Every time your solution is so elegant it leaves me speechless! Thank you!
Hi Anton,
You can try to implement such logic in the OnAfterFetch of your aggregate. In the OnAfterFetch, you will be able to use a lot of OutSystems built-in functions that might help you to achieve this.
Regards,
Prakhar Sharma
Hello @Anton Polyakov,
You can try the solutions suggested into the below posts.
https://www.outsystems.com/forums/discussion/86751/check-if-a-number-is-even-or-odd/
https://www.outsystems.com/forums/discussion/76990/how-to-check-if-a-number-is-even-or-odd/
Thanks,
Sachin
Hi,
You could also consider converting your aggregate in an Advanced SQL and then use the SQL % (modulo) operator:.
In order to fetch all the rows with an even column value, run:
SELECT * FROM my_entity WHERE my_attribute % 2 = 0;
Otherwise, if you want to fetch all the rows with an odd column value, run:
SELECT * FROM my_entity WHERE my_attribute % 2 <> 0;
Obviously, you have to adjust my sample SQL statements to follow OutSystems naming conventions and using your own aggregate an attributes.
Daniel