Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
Hi @wtaylor1 , I think you can try to use the Auto Refresh function to refresh the data source service to have it updated every 20 minutes.
Here is the example of the chart I am trying to populate:
Here is the Here is the code I am trying to use.
// Create a new service in ThingWorx
// Name: CreateRuntimeInfoTable
// Inputs: MashDate & Runtime_Min_Total
// Outputs: INFOTABLE (DataShape: RuntimeDataShape)
var result = Resources['InfoTableFunctions'].CreateInfoTableFromDataShape({
infoTableName: "InfoTable",
dataShapeName: "OEETImeBreakChart_DS",
});
// Define the start time and end time
var startTime = MashupDate;
startTime.setHours(6, 0, 0, 0); // 6:00 AM
var endTime = new Date();
endTime.setHours(18, 0, 0, 0); // 6:00 PM
// Define the interval in milliseconds (20 minutes)
var interval = 20 * 60 * 1000;
// Loop through the time range and add rows to the InfoTable
for (var time = startTime.getTime(); time <= endTime.getTime(); time += interval) {
// Query the Value Stream for the runtime value at the specific time
var query = {
oldestFirst: true,
maxItems: 1,
query: {
filters: {
type: "AND",
filters: [
{
type: "EQ",
fieldName: "timestamp",
value: dateFormat(new Date(time), "00:00:000"),
},
{
type: "EQ",
fieldName: "Runtime_Min_Total",
value: Things["KepConn_TruLaserWeldNPP"].Runtime_Min_Total,
},
],
}
},
};
var streamEntries = Things["KepConn_TruLaserWeldNPP"].QueryNamedPropertyHistory(query);
var runtimeValue = 0;
if (streamEntries.rows.length > 0) {
runtimeValue = streamEntries.rows[0].Runtime_Min_Total; // Replace 'Runtime' with the actual property name
}
var row = {
timestamp: new Date(time),
Runtime_Min_Total: runtimeValue
};
result.AddRow(row);
}
// Return the InfoTable
var output = result;