Skip to main content
7-Bedrock
May 16, 2024
Solved

how can i delete data in infotable

  • May 16, 2024
  • 2 replies
  • 1164 views

I want to delete data in the infotable by checking from the _time field. If there are any duplicate time periods, check from the day, month, year. Then delete rows that have a value of 0 from the infotable. What methods can be used to do this?

TW_10599876_0-1715850526973.png

 

Best answer by Rocko

Loop over the existing Infotable and create a new one containing only the required rows.

roughly like this (probably some syntax errors in it, but you'll get the idea):

let dateArray=[]; 
let oldTableArray=oldTable.rows.toArray();

// first pass: add non zero values, store dates in array
oldTableArray.filter(row=>row.value!=0).forEach(row=>{
   newTable.AddRow(row);
   dateArray.push(row._time.substring(0, 10));
});
// second pass: add zeroes if date not already contained in array built in first pass
oldTableArray.filter(row=>row.value==0 && !dateArray.includes(row._time.substring(0,10))).forEach(row=>{
   newTable.AddRow(row);
});

 

2 replies

16-Pearl
May 16, 2024

Hi @TW_10599876 

Can you check the below article and let us know it will work in your case or not.

https://www.ptc.com/en/support/article/CS304696

7-Bedrock
May 17, 2024

Now, I have succeeded by using the method of looping through the infotable to check the data.

 

Rocko
Rocko19-TanzaniteAnswer
19-Tanzanite
May 16, 2024

Loop over the existing Infotable and create a new one containing only the required rows.

roughly like this (probably some syntax errors in it, but you'll get the idea):

let dateArray=[]; 
let oldTableArray=oldTable.rows.toArray();

// first pass: add non zero values, store dates in array
oldTableArray.filter(row=>row.value!=0).forEach(row=>{
   newTable.AddRow(row);
   dateArray.push(row._time.substring(0, 10));
});
// second pass: add zeroes if date not already contained in array built in first pass
oldTableArray.filter(row=>row.value==0 && !dateArray.includes(row._time.substring(0,10))).forEach(row=>{
   newTable.AddRow(row);
});