How can I find the index of the original list while filtering in DMN

58 views
Skip to first unread message

Ravi Mangalagiri

unread,
Mar 1, 2022, 7:50:43 PM3/1/22
to Kogito development mailing list
Hi Kogito Team,

I have a list of people, and I am trying to filter them through a decision. In addition to the filtered list, I do need the original index

for example
Decision: people
[
{name: "Ravi", sex: "Male", age:46},    -- index:0
{name: "Ram", sex: "Male", age: 38}, -- index:1
{name: "Shyam", sex: "Male", age: 52}  -- index:2
]

Decision: filterPeople
people[age > 40] returns
[{name: "Ravi", sex: "Male", age:46},    -- index:0
{name: "Shyam", sex: "Male", age: 52}] -- index:2

Is it possible to filter the list and return the original list index?

Thanks
Ravi


--
Ravi Mangalagiri
703-505-4240 (c)

Matteo Mortari

unread,
Mar 2, 2022, 3:24:47 AM3/2/22
to Kogito development mailing list
Hi Ravi,
since FEEL list indexes are 1-based, this is a oneliner.

( for idx in 1..count(people) return { person: people[idx], index: idx } )[person.age>40]

Assuming you want as output a context with two entries, person for the original filtered item from the people collection, and index as its associated index.

Of course you can modify it to suit better if you want to return the indexes 0-based, in a trivial way (=> ... index: idx-1 ... )

HOpe this helps,
MM

--
You received this message because you are subscribed to the Google Groups "Kogito development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kogito-developm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kogito-development/CALg%3DC8Ni4Pob5zrntC5ug0aMVsewKOLMq%3DHcf2giY%3DEvZm5pjw%40mail.gmail.com.


--

Ravi Mangalagiri

unread,
Mar 2, 2022, 1:20:25 PM3/2/22
to Kogito development mailing list
Thanks, Matteo

It works. attached is the sample dmn for the context of the thread.

list.dmn
list.http
Reply all
Reply to author
Forward
0 new messages