Skip to main content
1-Visitor
January 30, 2020
Solved

Delete DataTable entry by timestamp

  • January 30, 2020
  • 25 replies
  • 11343 views

How might I go about deleting all items in a datatable by timestamp? Say over a year old? I am not seeing timestamp as a parameter of the DeleteDataTableEntriesWithQuery snippet.

Best answer by Constantine

Well, just create a ValueStream object, assign it to your thing (or thing template), make your totaldailysheetcount logged and see how it works -- it's really that simple, just execute GetPropertyHistory() on that thing again to see changes history. Check out Help on Value Streams -- it has all technical details.

25 replies

Support
January 30, 2020

Hi @Chao123.

 

Which version of ThingWorx are you running?

 

Regards.

 

--Sharon

Chao1231-VisitorAuthor
1-Visitor
January 31, 2020

Hello,

 

I believe it is 8.3.10-b1010

5-Regular Member
January 31, 2020

You can use a query ( inside the service) which will delete all data previous to the timestamp defined in value :

 

{

"filters": {

"type": "LT",

"fieldName": "timestamp",

"value": "2020-01-30"

}
}

 

Chao1231-VisitorAuthor
1-Visitor
January 31, 2020

Thank you for your suggestion. I am not doing this correctly obviously.

 

var query = {
"filters":{
"type": "LT",
"fieldName": "timestamp",
"values": "2020-01-30"
}
};

var result = me.DeleteDataTableEntriesWithQuery(query);

 

This will still delete all of my entries even if they are not LT the value. Not sure what I am doing wrong.

5-Regular Member
February 26, 2020

DeleteDataTableEntriesWithQuery is expecting a numeric value that represents milliseconds since epoch:

var query = {
 "filters": {
 "type": "LT",
 "fieldName": "timestamp",
 "value": new Date("2020-01-30")
 }
};