Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X
Hello Experts
I need to delete a range of data from a Stream.
How do I go about doing this? It is only for one things values though.
Help..
Solved! Go to Solution.
Excellent. Here is the working code:
var params = {
oldestFirst: undefined /* BOOLEAN */,
maxItems: undefined /* NUMBER */,
sourceTags: undefined /* TAGS */,
endDate: endDate /* DATETIME */,
query: undefined /* QUERY */,
source: source /* STRING */,
startDate: startDate /* DATETIME */,
tags: undefined /* TAGS */
};
// result: INFOTABLE
var result = Things["ApexReadingsStream"].QueryStreamEntriesWithData(params);
var stream = Things["ApexReadingsStream"];
for each(entry in result.rows) {
stream.DeleteStreamEntry({ streamEntryId: entry.id });
}
Hi Darryl, Stream or ValueStream?
Hi
Stream.
If you have to delete all the entries for a given period, you are lucky, you just need to use PurgeStreamEntries service. If you need to delete entries with a query condition, then you aren't that lucky, you have to query first and then execute one by one the service DeleteStreamEntry. For the second option, if you have to delete a lot of entries you will start having problems, well at least with Neo4J, we have a special code in order to delete entries in batch, now we are on PostgreSQL and we didn't had time to test if this problem that we had on Neo4J still persist on PostgreSQL...
For sure we need better services in order to delete Stream Entries out of the box.
Thanks Carles
Ya I am using Postgres. How do I put the multiple stream entry ID's into the form? Should I be separating them by comma?
Which form the mashup? the composer one?
Better you go with a custom service which accepts as imput stream entries, and loops on all the given entries and calls the DeleteStreamEntry, something like:
var stream = Things["StreamName"];
for each(entry in entries.rows) {
stream.DeleteStreamEntry({ streamEntryId: entry.id });
}
Tx Carles
That makes sense, but how would i tell it just just do a specific range? by id or by date?
I don't understand your question
i want to be able to specify the source, startDate and endDate as inputs for the service and then run the loop using those inputs.
Just use QueryStreamEntries service and give the result of this QueryStreamEntries to the custom DeleteStreamEntries that I've pointed out.
Thanks, am sure I am almost there:
ReferenceError: "entries" is not defined. (deleteEntriesStream#16)
var params = {
oldestFirst: undefined /* BOOLEAN */,
maxItems: undefined /* NUMBER */,
sourceTags: undefined /* TAGS */,
endDate: endDate /* DATETIME */,
query: undefined /* QUERY */,
source: source /* STRING */,
startDate: startDate /* DATETIME */,
tags: undefined /* TAGS */
};
// result: INFOTABLE
var stream = Things["ApexReadingsStream"].QueryStreamEntriesWithData(params);
//var stream = Things["StreamName"];
for each(entry in entries.rows) {
stream.DeleteStreamEntry({ streamEntryId: entry.id });
}
//var stream = Things["StreamName"];
for each(entry in entries.rows) {
stream.DeleteStreamEntry({ streamEntryId: entry.id });
}
Excellent. Here is the working code:
var params = {
oldestFirst: undefined /* BOOLEAN */,
maxItems: undefined /* NUMBER */,
sourceTags: undefined /* TAGS */,
endDate: endDate /* DATETIME */,
query: undefined /* QUERY */,
source: source /* STRING */,
startDate: startDate /* DATETIME */,
tags: undefined /* TAGS */
};
// result: INFOTABLE
var result = Things["ApexReadingsStream"].QueryStreamEntriesWithData(params);
var stream = Things["ApexReadingsStream"];
for each(entry in result.rows) {
stream.DeleteStreamEntry({ streamEntryId: entry.id });
}