cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

Function to update stream entries

a-dub
3-Newcomer

Function to update stream entries

All..

 

I have a stream with data coming in. I'd like to create or use a service to update stream entries. 

 

End goal would be for the service to have 3 inputs (start,end,tag) so the service would add the "tag" tag to all entries between "start" datetime and "end" datetime.

 

I see the built in "UpdateStreamEntry" so I suppose I could query all stream entries between the two datetimes, and then loop through that entire query result calling UpdateStreamEntry each time.

 

However, I'd like to know if there is already a pre-built function to do this?

 

Thanks

ACCEPTED SOLUTION

Accepted Solutions

You have the service QueryStreamEntriesWithData in order to query the data, and then you can iterate over each previous result and use UpdateStreamEntry

View solution in original post

2 REPLIES 2

You have the service QueryStreamEntriesWithData in order to query the data, and then you can iterate over each previous result and use UpdateStreamEntry

a-dub
3-Newcomer
(To:CarlesColl)

Here is some code I developed for this task (if anyone wants to re-use). You can replace GetStreamEntriesWithData service with QueryStreamEntriesWithData to use like CarlesColl said.

 

var table =  me.GetStreamEntriesWithData({
	oldestFirst: true /* BOOLEAN */,
	maxItems: 15 /* NUMBER */
});

var row;
var tableLength = table.rows.length;

for (var x=0; x < tableLength; x++) {
    row = table.rows[x];
    
    row.tags.AddTag("BatchNumbers","D000001");
    
    me.UpdateStreamEntry({
		values: me.CreateValuesWithData({
        	values: {column1: row.column1,
                        column2:  row.column2,
                        column3:  row.column3,
                        column4:  row.column4,
                        column5:  row.column5,
                        column6:  row.column6,
                        column7:  row.column7} /* JSON */
                    }) /* INFOTABLE */,
		streamEntryId: row.id /* STRING */,
		location: row.location /* LOCATION */,
		source: row.source /* STRING */,
		tags: row.tags /* TAGS */
	});
}

var result =  me.GetStreamEntriesWithData({
	oldestFirst: true/* BOOLEAN */,
	maxItems: 20 /* NUMBER */
});

 

Announcements


Top Tags