Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X
Hi all,
Getting error while executing AddStreamEntries service:
JavaException: java.lang.Exception: Invalid number of values provided to AddStreamEntry
let newEntry = {
sourceType: undefined, // STRING
values: entries, // INFOTABLE
location: undefined, // LOCATION
source: undefined, // STRING
tags: undefined, // TAGS
timestamp: new Date() // DATETIME
};
// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(StreamEntryWithValues)
let obj = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
infoTableName: "InfoTable",
dataShapeName: "StreamEntryWithValues"
});
obj.AddRow(newEntry);
me.AddStreamEntries({
values: obj /* INFOTABLE {"dataShape":"StreamEntryWithValues"} */
});
Thanks,
Sujith
Solved! Go to Solution.
use below service
Things["TestStream"].AddStreamEntries({
values: dataset/* INFOTABLE */
});
"dataset" is the nested infotable as below, which uses "StreamEntryWithValues" datashape.
In "StreamEntryWithValues" datashape, there is one infotable field called "values"
In "values" infotable, you will have your own data set.
Each row consider as one entry in stream.
Hope it helps
//TestValuestream is the value stream name
let values = Things["TestValuestream"].CreateValues();
values.x = new Date(); //your datashape fields
values.y = 10; //your datashape fields
let params = {
tags: undefined,
timestamp: new Date(),
source: me.name,
values: values,
location: undefined
};
Things["TestValuestream"].AddStreamEntry(params);
result = values;
try above code
Hi @Sathishkumar_C ,
I want to add multiple entries to the Stream at once, not only one entry.
Thanks,
Sujith
use below service
Things["TestStream"].AddStreamEntries({
values: dataset/* INFOTABLE */
});
"dataset" is the nested infotable as below, which uses "StreamEntryWithValues" datashape.
In "StreamEntryWithValues" datashape, there is one infotable field called "values"
In "values" infotable, you will have your own data set.
Each row consider as one entry in stream.
Hope it helps
I tried using "AddStreamEntries" service but I get this error:
Error executing service getPwrSupplyErrorReport. Message :: Wrapped java.lang.NullPointerException - See Script Error Log for more details.
How can I fix this?
it might be because of passing null values to the integer/number fields. Please share code here, if possible.
yes below is my code:
//creating an infotable
let Log = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
infoTableName: "InfoTable",
dataShapeName: "DataShape"
});
//Defining date variable
var currentDate;
//assigning valueList variable to my infoTable property that contains values (current it only has one row)
var valuesList = Things["TestThing1"].infoTableThingProperty;
//loop through the infotable above
for(var i=0; i<valuesList.length; i++){
// new object
newEntry = {
duration:valuesList[i].duration,
source: valuesList[i].Source,
Name: valuesList[i].Name,
Type: valuesList[i].Type,
StartTime: valuesList[i].StartTime,
EndTime: valuesList[i].faultEndTime,
Voltage: valuesList[i].Voltage,
Text: valuesList[i].Text
};
//adding my object values to the infotable
Log.AddRow(newEntry);
}
//adding my infotable to the stream
var newLog = Things["SinkWorx.PwrSupplyError_Stream"].AddStreamEntries({
values: Log /* INFOTABLE {"dataShape":"StreamEntryWithValues"} */
});
//output result
let result = Log;