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

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

Unable to execute addStreamEntries

chaitanya
7-Bedrock

Unable to execute addStreamEntries

I have assigned a dataShape(without a primary key) to a stream but whenever I try to edit value field to add multiple stream entries. I get a response saying "Must have a dataShape defined to add rows. "(Please find attached screenshot)

When tried with a single addEntry, it works fine.

4 REPLIES 4
PaiChung
22-Sapphire I
(To:chaitanya)

It looks like you are trying to execute this within composer.

Unfortunately it looks like this is one of those services that doesn't run within composer.

You will have to do an actual service call.

Hi @PaiChung,

Thanks for the response.
Do you mean to say I have to invoke this service with a REST call?
If so, what would be the json structure for sending multiple entries?

I tried using below service. It executes successfully but when GetStreamEntriesWithData is called, I am unable to see any added entries.
/////////////////////

// *** SET UP META DATA FOR INFO TABLE ***

// create a new InfoTable based on AddStreamEntries parameters (timestamp, location, source, sourceType, tags, values)

var myInfoTable = { dataShape: { fieldDefinitions : {} }, rows: [] };

myInfoTable.dataShape.fieldDefinitions['timestamp'] = { name: 'timestamp', baseType: 'DATETIME' };

myInfoTable.dataShape.fieldDefinitions['location'] = { name: 'location', baseType: 'LOCATION' };

myInfoTable.dataShape.fieldDefinitions['source'] = { name: 'source', baseType: 'STRING' };

myInfoTable.dataShape.fieldDefinitions['sourceType'] = { name: 'sourceType', baseType: 'STRING' };

myInfoTable.dataShape.fieldDefinitions['tags'] = { name: 'tags', baseType: 'TAGS' };

myInfoTable.dataShape.fieldDefinitions['values'] = { name: 'values', baseType: 'INFOTABLE' };

// *** SET UP ACTUAL VALUES FOR INFO TABLE ***

// create new meta data

var tags = new Array();

var timestamp = new Date();

var location = new Object();

location.latitude = 0;

location.longitude = 0;

location.elevation = 0;

location.units = "WGS84";

// add rows to InfoTable (~5 times)

for (i=0; i<5; i++) {

// create new values based on Stream DataShape

var params = {

infoTableName : "Infotable2",

dataShapeName : "testDs2"

};

var values = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);

// add something to the values to make them unique

// create and add new row based on Stream DataShape

// only a single line allowed!

var newValues = new Object();

newValues.a = "aaa" + i; // STRING - isPrimaryKey = true

newValues.b = "bbb" + i; // STRING

newValues.c = "ccc" + i; // STRING

values.AddRow(newValues);

// create new InfoTable row based on meta data & values

// add 10 ms to each object, to make it's timestamp unique

// otherwise entries with the same timestamp will be overwritten

var newEntry = new Object();

newEntry.timestamp = new Date(Date.now() + (i * 10));

newEntry.location = location;

newEntry.source = me.name;

newEntry.tags = tags;

newEntry.values = values;

// add new Info Table row to Info Table

myInfoTable.rows = newEntry;

}

// *** ADD myInfoTable (HOLDING MULITPLE STREAM ENTRIES) TO STREAM

// add stream entries in the InfoTable

var params = {

values: myInfoTable /* INFOTABLE */

};

// no return
var result = params.values;

Things["MyStreamThing"].AddStreamEntries(params);

///////////////////////////

PaiChung
22-Sapphire I
(To:chaitanya)

 

It doesn't look like you are doing anything wrong, although infotable inside of infotable is tricky.

I'd recommend you create a support ticket for this.

Announcements


Top Tags