Getting Last Object payload for an array that varies


What is the best way to get the last object payload from a sql array.

I am calling a sql server which depending on datatime pulls different amount a results. I need that last object payload to display on the dashboard

I would like to get the information from object 42 during this example.

How can i adjust [0] in below example.
{{msg.payload[0].EmployeeNumber}} for the dashboard



The method length will indicate the array size. The last element is array size -1 , so you could try using:




Alternatively if you are not using the earlier ones at all then change the SQL query so it only returns the last one.
Alternatively again you could change the sort order on the query to return them in the opposite order then it would always be [0].

1 Like


That solution worked great.

1 Like


The only option I was giving by the person who set the database up was to exec with the start and end date/time. I needed to read the last person thru the gate to display some information



Not much of a database if you can't query for the last record. Still, you have a solution so that is the main thing.

1 Like