Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X
Hi Team,
Just like to get N no of rows from top in any infotable ThingWorx provides default snippet as TopN method of InfotableFunctions , do we have any snippet to get Last N rows of any infotable?
Please share the snippet.
Thanks in advance.
Solved! Go to Solution.
@VladimirRosu @TonyZhang @VladimirN
For now I have ignored the rows from starting which I don't want in my final infotable via for loop but it will be good to have some method which can provide Last N rows also of an infotable just like TopN method.
Hi,
There was a similar question before - "How to get certain number of rows from Infotable": https://community.ptc.com/t5/ThingWorx-Developers/How-to-get-certain-number-of-rows-from-Infotable/td-p/610708
@VladimirN The link shared is for First N Rows the method is TopN. But I need Last N Rows of an infotable.
Currently there's no LastN or BottomN snippet available but might be released in the future.
You can post your idea in below site.
https://community.ptc.com/t5/ThingWorx-Ideas/idb-p/thingworxideas
For now you can consider using built-in Sort function (snippet) to sort on a column in descending order so you get your infotable rearranged in reversed order.
Then use TopN to extract the rows you want.
And a (very simple) code-based alternative is the following:
// Simulation.DataShape is a custom DataShape I used for this test
let result = DataShapes["Simulation.DataShape"].CreateValues();
// test is the input infotable
let length = test.getRowCount();
// slice is a built in Javascript array method that will get us the last 2 rows in this situation; replace 2 with the desired number of last rows
test.rows.toArray().slice(length-2,length).forEach(row=>{result.addRow(row);});
@VladimirRosu @TonyZhang @VladimirN
For now I have ignored the rows from starting which I don't want in my final infotable via for loop but it will be good to have some method which can provide Last N rows also of an infotable just like TopN method.