Retrieve last inserted element from list

0
Hello,   I have a list retrieved by association and i need to get last inserted element from that list.   Need some help with this please.   Thank you in advance.
asked
3 answers
0

Hey Anna,

The easiest way would be to sort the list (to reverse its order) and then use the list operation with the "Head" function to obtain the first object in that list.

image.png

 

You can read more about this here: https://docs.mendix.com/refguide/list-operation/

 

I hope it helps!

answered
0

Hey Anna,

 

IMO Mendix currently doesn't offer direct implementation to retrieve the last element of the list. If you are in Mendix version 9.24.4+ then Mendix offers list operation "Range"

https://docs.mendix.com/refguide/list-operation/#range

 

With the help of this, you should able to get last inserted element. So in this case amount will be 1, and offset should be length of list -1.

 

If this not works, then you can go for lengthy method where at time of setting association you also maintain an order and then sort on it in descending manner and then get the first object.

 

Thanks & Regards,

Naman Khard

answered
0

Thank you for your replies!

answered