Skip to main content
1-Visitor
March 14, 2017
Question

Unable to transfer data from Infotable to Stream

  • March 14, 2017
  • 2 replies
  • 4177 views

Hi,

I want to transfer data from Infotable to  a Stream.

I tried this:

Thingame = "THGF_LPIPPO1";  

STREAM   = "THGF_LPIPPO1STREAM";

var grid = Things[Thingame].Cont_Grid;

var length  = grid.rows.length;

   for (var j=0;j<length;j++){

        var row = grid.rows;

// val:INFOTABLE(Datashape: DSHP_STREAMSTORICO)

       var val = Things[STREAM].CreateValues();

        val.ValoreBonus = row.ValoreBonus; //STRING

        val.NumGettoniErogati = row.NumGettoniErogati; //STRING

        val.CreditoIniziale = row.CreditoIniziale; //STRING

        val.FasciaOraria = row.FasciaOraria; //STRING

        val.TipoEvento = row.TipoEvento; //STRING

        val.ValoreRicaricato = row.ValoreRicaricato; //STRING

        val.Codice = row.Codice; //STRING

        val.NumGettBonus = row.NumGettBonus; //STRING

        val.Timestamp = row.Timestamp; //DATETIME

        val.PrezzoSelezione = row.PrezzoSelezione; //STRING

        val.NumSelezione = row.NumSelezione; //STRING

        val.CreditoInserito = row.CreditoInserito; //STRING

        val.Overpay = row.Overpay; //STRING

        val.MatricolaChiave = row.MatricolaChiave; //STRING

        val.RestoErogato = row.RestoErogato; //STRING

        var params =

       {

            values : val

        };

        Things[STREAM].AddStreamEntry(params);

    }

This worked but this script copy one row from the infotable to the Stream, in particular the oldest.

So I noticed this snippet:

var params = {

  values: grid    /* INFOTABLE */

};

// no return

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

but I have the following error:

Wrapped java.lang.NullPointerException Cause: null

Can you help me???

Thanks

Thingworx: 7.2.6

2 replies

20-Turquoise
March 14, 2017

Hi, you would need to assign matching datashapes to the input infotable as well as the stream. Here's an example, for my input infotable "yourit", stream TestStream. with datashape dsstream

mvolanti1-VisitorAuthor
1-Visitor
March 15, 2017

I tried this, i want to transfer this: (ALL THE ROWS)

into the stream, with this:

Run the service first time and in the STREAM :

Second Time:

third and 4th time:

    Don't transfer all Codice : 1,2,3,4

Can you try with multiple Rows??

15-Moonstone
March 15, 2017

Hi Maurizio,

You should probably use ​getRowCount() snippet to get amount of rows in your InfoTable property. I am not sure if your way of getting length of InfoTable is correct.

3.PNG

Best Regards,

Adam

14-Alexandrite
March 15, 2017

You should just be able to use the AddStreamEntries service and pass in the full infotable, as long as the infotable and stream have the same datashape (which you noted they do).  This seemed to give an error so looping may help to determine why.

Also to loop through a json array (which is what the rows element of an infotable actually is) I use the following structure as it's simpler...

You should then also be able to just use the row variable for your input parameter if you are adding one at a time.  No need to redefine the input object...

for each (row in grid.rows) {

     var params ={ values : row};

     Things[STREAM].AddStreamEntry(params);

}