Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X
Hi there,
I'd like to know what is the best way to find the earliest (first) timestamp in the value stream. Code below does work, but it takes a long time if there are few propertyNames. It necessary to know at what point data became available. I'd be grateful for your advise, thanks!
var endDate = new Date();
var startDate = new Date();
startDate.setYear(2000);
var params = {
oldestFirst: true /* BOOLEAN */,
maxItems: maxitems /* NUMBER */,
endDate: endDate /* DATETIME */,
propertyNames: propertyNames /* INFOTABLE */,
query: undefined /* QUERY */,
startDate: startDate /* DATETIME */
};
// result: INFOTABLE dataShape: "undefined"
var myQuery = Things[thing].QueryNamedPropertyHistory(params);
var result = myQuery.rows[0].timestamp; //DATETIME
It may be faster to simply limit your query to a single returned item. You're passing in "Oldest first", which means the first row that you're getting is already the oldest row. Everything beyond that would be unnecessary data to transfer from the database and could slow things down.
Start by setting maxItems to 1 and see if that returns faster and gives you what you need.