Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X
hello I am having a data table into which values are being inserted at regular intervals.
I want to show last 5 entries of the data table.
Hi dibya ranjan mishra,
Data table is not queried based on timestamp. As per my understanding you should use Stream so that Data can queried based on time and last 5 entries can be fetched.
If you are using Streams; you can simply use GetStreamEntriesWithData and set oldestFirst as false and maxItems as 5.
For Data Table you will have to create your own custom query to find the last 5 entries; Performance could be low.
You could try following:
Read the data for last x hours based on frequency of Data. Then sort the infotable based on timestamp (desending) and then read first 5 rows.
I hope it helps.
Here is what I did to fetch the last 5 records:
// result: INTEGER
var length = me.GetDataTableEntryCount();//your starting ID +length will be the last record ID
var query = {
"filters": {
"fieldName": "id",
"type": "GE",
"value": length-4
}};var params = {
maxItems: undefined /* NUMBER */,
values: undefined /* INFOTABLE*/,
query: query /* QUERY */,
source: undefined /* STRING */,
tags: undefined /* TAGS */
};// result: INFOTABLE dataShape: "undefined"
var result = me.QueryDataTableEntries(params);
This is based on that you have a sequenced ID(start from 1 for example, and increased by 1 every time there was a new entry, or you change the code according your ID generator)
Hope it will helps,
Br,
Anna
Is there still anything issue with your service? Please let us know if further assistance needed.
Thanks,
Br,
Anna