Skip to main content
Jan 30, 2020 7:21 PM UTC
Solved

Delete DataTable entry by timestamp

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.

Feb 27, 2020 5:41 PM UTC

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

Jan 30, 2020 7:47 PM UTC

Hi @Chao123.

 

Which version of ThingWorx are you running?

 

Regards.

 

--Sharon

Chao123Author
Jan 31, 2020 3:45 PM UTC

Hello,

 

I believe it is 8.3.10-b1010

Jan 31, 2020 8:44 AM UTC

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"

}
}

 

Chao123Author
Jan 31, 2020 6:43 PM UTC

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.

Feb 26, 2020 6:25 PM UTC

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

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