Hi,
If I need to get the vehicles Data where ID in {1,2,3}, I can do this :
index( ri!vehicles, wherecontains( {1, 2, 3}, ri!vehicles.id ) )
But is there any way to do the same thing with a negation (a kind of notWhereContains) ? I mean I need to get the vehicles data where ID not in {1, 2, 3}.
Of course, I can then use a foreach to get the correct data, or create an exclusion list items, to apply the whereContains on the latter,
but is there any other way to do it with a single simple instruction ?
Discussion posts and replies are publicly visible
Can you not create a list using wherecontains() and then use the set function 'difference' to get those items NOT in the list you just generated?
Yes of course... when I was talking about "create an exclusion list items" it is exactly the difference I was thinking about.
You can also simply wrap it into a not().
A foreach() is not directly meant to be used for filtering as it creates a list with an output item for each input item. This is heavily discussed here in case you want to explore that.
Stefan, can you modify my example with a "not()" please ? I'm not sure to see what your mean
I think I was reading your code too fast. Does not make any sense ...
ah ok, that reassures me ;-)
Agree with Stewart! Sample code:
index( ri!vehicles, difference( ri!vehicles.id, wherecontains( {1, 2, 3}, ri!vehicles.id ) ) )
Yes, of course it works well with the Difference function, but I was looking for another simple way.but thank you for your reply.
whereContains() essentially does this:
a!forEach( items: ri!array, expression: if( contains( ri!values, fv!item ), fv!index, {} ) )
Therefore you could create your own "where not contains" rule by flipping the internal logic of this:
a!forEach( items: ri!array, expression: if( contains( ri!values, fv!item ), {}, fv!index ) )
Thank you Mike, very interesting.
Initially a was using Foreach to make the "where not contain", then, I've tested Difference too.
In any case an internal foreach is used, so it does reply to my question...and I have some choice now :-)