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.
image

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:

{{msg.payload[msg.payload.length-1].EmployeeNumber}}

1 Like

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].

2 Likes

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

thanks againg :vulcan_salute:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.