3 Replies Latest reply on Jun 27, 2017 4:40 AM by anna RSS
    dmishra Newbie

    how to get the last 5 entries from the data table

    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.

      • Re: how to get the last 5 entries from the data table
        Ankit Gupta Ninja

        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.

        • Re: how to get the last 5 entries from the data table
          anna Communicator

          dibya ranjan mishra,

          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

          • Re: how to get the last 5 entries from the data table
            anna Communicator

            dibya ranjan mishra,

            Is there still anything issue with your service? Please let us know if further assistance needed.

             

            Thanks,

             

            Br,

            Anna