Let's consider that we have two Streams Stream1 and Stream2 with same DataShape StreamDS.

DataShape StreamDS has two fields Id (number) and Name (string).

We want to copy all the entries from Stream1 to Stream2.

 

Steps:

1. Open Stream1 Stream in Composer and run GetStreamEntriesWithData service.

2. In the popup click on Create DataShape from Result option to create a new DataShape GetStreamEntriesDS.

3. Create a Service and use JavaScript like below (Added Comments for Details):

// Create Temporary Infotable to hold output of GetStreamEntriesWithData Service
var paramsForInfotable = {
  infoTableName: "InfoTable" /* STRING */,
  dataShapeName: "GetStreamEntriesDS" /* DATASHAPENAME */
};


// result: INFOTABLE
var InfotableForCopy = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(paramsForInfotable);


//Save output of GetStreamEntriesWithData Service to Temporary Infotable InfotableForCopy
var paramsForGetStreamEntriesWithDataService = {
  oldestFirst: false /* BOOLEAN */,
  maxItems: 10000 /* NUMBER */
};


// result: INFOTABLE dataShape: "GetStreamEntriesDS"
InfotableForCopy = Things["Stream1"].GetStreamEntriesWithData(paramsForGetStreamEntriesWithDataService);


// Read the data from Infotable row by row and add it to new Stream
var tableLength = InfotableForCopy.rows.length;


for (var x = 0; x < tableLength; x++) {
  var row = InfotableForCopy.rows[x];


// values:INFOTABLE(Datashape: StreamDS)
var values = Things["Stream2"].CreateValues();


values.Id = row.Id; //NUMBER
values.Name = row.Name; //STRING


var paramsForAddStreamEntryService = {
  sourceType: row.sourceType /* STRING */,
  values: values /* INFOTABLE*/,
  location: row.location /* LOCATION */,
  source: row.source /* STRING */,
  timestamp: row.timestamp /* DATETIME */,
  tags: row.tags /* TAGS */
};


// AddStreamEntry(tags:TAGS, timestamp:DATETIME, source:STRING, values:INFOTABLE(StreamDS), location:LOCATION):NOTHING
Things["Stream2"].AddStreamEntry(paramsForAddStreamEntryService);
}


var result = InfotableForCopy;