Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X
I have entry saved in Datatable and entry contains an infotable in it and i have two entries in it and i want to delete one of the version data from it which is on index 1. I have attached the screenshot also.
I have written a code which is removing the infotable value which is on index 1 but i am unable to update the datatable. Can someone please see whats a mistake here.
let entry = Things["TestBench_Entries_SCW1.DT"].GetDataTableEntryByKey({key:"1709798512000SCW1E-SCW-SEM-01"});
logger.info("1"+entry.rows);
let values;
if ( entry.rows[0].versionData && entry.rows[0].versionData.rows && entry.rows[0].versionData.rows.length > 1 ) {
//logger.info("2" + entry.rows[0].versionData.RemoveRow(1));
values = Things["TestBench_Entries_SCW1.DT"].CreateValues();
values.entryTimeStamp = entry.rows[0].entryTimeStamp; // STRING [Primary Key]
values.Location = entry.rows[0].Location; // INFOTABLE
values.Position = entry.rows[0].Position; // DATETIME
values.entryDate = entry.rows[0].entryDate; // STRING
values.status = entry.rows[0].status;// STRING
values.tinNumber = entry.rows[0].tinNumber;// STRING
values.versionData = entry.rows[0].versionData.RemoveRow(1);// STRING
}
logger.info("Jamal" +entry.rows[0].versionData.rows.length);
Things["TestBench_Entries_SCW1.DT"].AddOrUpdateDataTableEntry({values:values});
result = entry;
now funny thing is i have just set a logger to remove it and in result it shows me the infotable with removed that entry but here in this code i get null ==> entry.rows[0].versionData.RemoveRow(1)
Solved! Go to Solution.
I have found a solution. This logger.info("2" + entry.rows[0].versionData.RemoveRow(3));
// This logger is already removing the object from array which is on 3rd Index. Even though its a logger it still removes the object. So finally i am able to delete the infotable row and updates again into the datatable.
let entry = Things["TestBench_Entries.DT"].GetDataTableEntryByKey({key:"1709102797000SCW"});
logger.info(entry.rows);
let values;
if ( entry.rows[0].versionData && entry.rows[0].versionData.rows && entry.rows[0].versionData.rows.length > 1 ) {
logger.info("2" + entry.rows[0].versionData.RemoveRow(3)); // This logger is already removing the object from array which is on 3rd Index. Even though its a logger it still removes the object.
values = Things["TestBench_Entries.DT"].CreateValues();
values.entryTimeStamp = entry.rows[0].entryTimeStamp; // STRING [Primary Key]
values.Location = entry.rows[0].Location; // INFOTABLE
values.Position = entry.rows[0].Position; // DATETIME
values.entryDate = entry.rows[0].entryDate; // STRING
values.status = entry.rows[0].status;// STRING
values.tinNumber = entry.rows[0].tinNumber;// STRING
values.versionData = entry.rows[0].versionData;// STRING
}
//logger.info(entry.rows[0].versionData);
Things["TestBench_Entries.DT"].AddOrUpdateDataTableEntry({values:values});
result = entry;
I have found a solution. This logger.info("2" + entry.rows[0].versionData.RemoveRow(3));
// This logger is already removing the object from array which is on 3rd Index. Even though its a logger it still removes the object. So finally i am able to delete the infotable row and updates again into the datatable.
let entry = Things["TestBench_Entries.DT"].GetDataTableEntryByKey({key:"1709102797000SCW"});
logger.info(entry.rows);
let values;
if ( entry.rows[0].versionData && entry.rows[0].versionData.rows && entry.rows[0].versionData.rows.length > 1 ) {
logger.info("2" + entry.rows[0].versionData.RemoveRow(3)); // This logger is already removing the object from array which is on 3rd Index. Even though its a logger it still removes the object.
values = Things["TestBench_Entries.DT"].CreateValues();
values.entryTimeStamp = entry.rows[0].entryTimeStamp; // STRING [Primary Key]
values.Location = entry.rows[0].Location; // INFOTABLE
values.Position = entry.rows[0].Position; // DATETIME
values.entryDate = entry.rows[0].entryDate; // STRING
values.status = entry.rows[0].status;// STRING
values.tinNumber = entry.rows[0].tinNumber;// STRING
values.versionData = entry.rows[0].versionData;// STRING
}
//logger.info(entry.rows[0].versionData);
Things["TestBench_Entries.DT"].AddOrUpdateDataTableEntry({values:values});
result = entry;