Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
I have an Infotable property that is enabled for logging and is persistent.
This Infotable contains three columns: Number, StartDate, and EndDate. The table is updated every 24 hours.
The update logic is as follows:
While this updates the Infotable with the new values (updated dates), when I query it using QueryNamedPropertyHistory or QueryInfoTablePropertyHistory, I only see one log entry for the property instead of a complete history.
Could you help me understand why the logs aren’t being recorded as expected?
Thingworx version -> 9.3.8
Solved! Go to Solution.
You probably have to set the "" in the property configuration to "On" for property type Infotable.
Those variables are just pointers to objects in memory, so if you don't create a new object, ThingWorx won't know that you modified the content and so it won't overwrite the value in the database. Try to create a new object by cloning your property first:
let it = Resources["InfoTableFunctions"].Clone({ t1: me.property });
/ Constantine
Thank you! However, in my case, I am creating a new Infotable and adding rows to it. Here's my code.
shift = Things[Thingname].StandardShiftTime;
for(l=0;l<shift.getRowCount();l++){
sd = shift[l].StartDate;
ed = shift[l].EndDate;
var SDate = new Date(sd); // Replace this with your desired date
SDate.setDate(SDate.getDate() + 1);
var EDate = new Date(ed);
EDate.setDate(EDate.getDate() + 1);
// Shift.DS entry object
let newEntry = {
Shift: shift[l].Shift, // INTEGER
StartDate: SDate, // DATETIME
EndDate: EDate // DATETIME
};
outputtable.AddRow(newEntry);
}
Things[Thingname].StandardShiftTime = outputtable;
Well, one of the reasons why it doesn't log changes might be because the scheduler fails, for example the user who runs it doesn't have enough permissions to execute this code. Are you sure it executes correctly every 24h, do you log it somewhere? Are changes saved in the property and its history when you run this code yourself in Composer?
Also, instead of "Things[Thingname].StandardShiftTime = outputtable" you can use SetPropertyValues explicitly:
let props = Resources["InfoTableFunctions"].CreateInfoTable();
props.AddField({ name: 'StandardShiftTime', baseType: 'INFOTABLE' });
props.AddRow({ StandardShiftTime: outputtable });
Things[Thingname].SetPropertyValues({ values: props });
See details here: https://www.ptc.com/en/support/article/CS221424
/ Constantine
Yes , The Script work correctly and does update the values for the infotable property. But it does not log , as result cannot be seen query.
I initially tried using only setProperty(), but it didn't work. After changing the data type to 'ON', I was able to see it in the logs.
Thank you!
Sharing the updated code that successfully logs the InfoTable.
try {
// Get the name of the current Thing (object)
let thingName = me.name;
// Clone the existing InfoTable (me.Table) to create a copy for modification
let clonedTable = Resources["InfoTableFunctions"].Clone({ t1: me.Table });
// Iterate over each row in the cloned table and update the ShiftStart and ShiftEnd dates
clonedTable.rows.toArray().forEach(row => {
// Add 1 day to both ShiftStart and ShiftEnd fields
row.ShiftStart = dateAddDays(row.ShiftStart, 1);
row.ShiftEnd = dateAddDays(row.ShiftEnd, 1);
});
// Create a new InfoTable to hold the updated table data
let updatedProps = Resources["InfoTableFunctions"].CreateInfoTable();
// Define a field named 'Table' in the new InfoTable with base type 'INFOTABLE'
updatedProps.AddField({ name: 'Table', baseType: 'INFOTABLE' });
// Add a row to the InfoTable containing the updated table
updatedProps.AddRow({ Table: clonedTable });
// Set the updated properties back to the Thing
Things[thingName].SetPropertyValues({ values: updatedProps });
// Return the updated InfoTable as the result
result = updatedProps;
} catch (err) {
logger.error("{} - {}:{} - {}", me.name, err.fileName || "Unknown File", err.lineNumber || "Unknown Line", err);throw new Error("An error has occurred on line " + (err.lineNumber || "unknown") + ". Please check the script logs for more details.");
}
You probably have to set the "" in the property configuration to "On" for property type Infotable.
Thank you!
This helped me log the InfoTable, and now I can see it using both QueryPropertyHistory and QueryInfoTableHistory.
SD
I encountered a similar issue, but as @Rocko suggested, changing the data change type to "On" allowed me to see the log history for the infotable property.