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

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

How to create a nested Infotable in a stream

Tomellache2B
14-Alexandrite

How to create a nested Infotable in a stream

Good day Community,

 

I have a stream and I write to this stream in serviceA. 

The stream  has a field of type infotable.

So when adding a row to the stream in serviceA, I do not add anything to the nested infotable yet.

I have service B where I intend to write to the nested infotable.

This is my code:

let Stream = Shaft_Name;


// result: INFOTABLE dataShape: ""


let Stream_Data = Things[Stream].QueryStreamEntriesWithData({
oldestFirst: undefined /* BOOLEAN */,
maxItems: undefined /* NUMBER {"defaultValue":500} */,
sourceTags: undefined /* TAGS */,
endDate: undefined /* DATETIME */,
query: undefined /* QUERY */,
source: undefined /* STRING */,
startDate: undefined /* DATETIME */,
tags: undefined /* TAGS */
});


let Updated_Info = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
infoTableName: "InfoTable",
dataShapeName: "ShaftSinkingCycleDelayInfo_DS"
});
let len = Stream_Data.length;
let Activity_Unique_Id;
let Delay_Info;


for(let i=0; i<len; i++){//Looping through the stream
Activity_Unique_Id = Stream_Data[0].activity_unique_id;//get the specific row to update 

input


let x = Activity_Unique_Id;
Updated_Info.AddRow({delay_id:x});


 Things["Stream"].AddStreamEntry({
 sourceType: undefined /* STRING */,
 values: Updated_Delay_Info /* INFOTABLE */,
 location: undefined /* LOCATION */,
 source: me.name /* STRING */,
 timestamp: undefined /* DATETIME */,
 tags: undefined /* TAGS */
 });
Updated_Info.RemoveAllRows();

}
let result = Stream_Data[Delay_Information];//outputting the nested infotable

 

 

I do not get the nested infotable. 

How can do I write to a column inside a nested infotable?

 

Regards,

 

1 ACCEPTED SOLUTION

Accepted Solutions
DanZ
15-Moonstone
(To:Tomellache2B)

 

for(let i=0; i<len; i++){//Looping through the stream
Activity_Unique_Id = Stream_Data[0].activity_unique_id; //get the specific row to update 

 

 If you want to iterate and not always assign the first row of of the stream to "Activity_Unique_Id", you should change the [0] to [i].

 

EDIT: I am missing some context to your service snippet. Because your variable "Updated_Delay_Info" that you put in your "value" property is nowhere defined. And a few other things...

 

Anyhow: The "values" infotable for "AddStreamEntry" must be the datashape that is used for the stream entity. I am not sure if that is "

ShaftSinkingCycleDelayInfo_DS" or if this is just the datashape for the nested infotable.
 
So... create infotable "A" with the datashape of the nested infotable and add your rows there. Then create another infotable "B" with the datashape of the stream you want to write into. Simply add the variable that contains infotable A to the value collection for infotable B (like for any other data type). And now call "AddStreamEntry" with infotable B.

 

 

 

 

View solution in original post

1 REPLY 1
DanZ
15-Moonstone
(To:Tomellache2B)

 

for(let i=0; i<len; i++){//Looping through the stream
Activity_Unique_Id = Stream_Data[0].activity_unique_id; //get the specific row to update 

 

 If you want to iterate and not always assign the first row of of the stream to "Activity_Unique_Id", you should change the [0] to [i].

 

EDIT: I am missing some context to your service snippet. Because your variable "Updated_Delay_Info" that you put in your "value" property is nowhere defined. And a few other things...

 

Anyhow: The "values" infotable for "AddStreamEntry" must be the datashape that is used for the stream entity. I am not sure if that is "

ShaftSinkingCycleDelayInfo_DS" or if this is just the datashape for the nested infotable.
 
So... create infotable "A" with the datashape of the nested infotable and add your rows there. Then create another infotable "B" with the datashape of the stream you want to write into. Simply add the variable that contains infotable A to the value collection for infotable B (like for any other data type). And now call "AddStreamEntry" with infotable B.

 

 

 

 

Top Tags