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

Unable to transfer data from Infotable to Stream

Highlighted
Regular Member

Unable to transfer data from Infotable to Stream

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

Tags (2)
6 REPLIES 6
Highlighted

Re: Unable to transfer data from Infotable to Stream

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

Re: Unable to transfer data from Infotable to Stream

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??

Highlighted

Re: Unable to transfer data from Infotable to Stream

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

Highlighted

Re: Unable to transfer data from Infotable to Stream

Is correct.

if you try:

var length  = grid.rows.length;

logger.warn(length);

you have the correct length. this stamp in the monitoring>script.

Can you try my code to transfer infotable to stram?

Thanks

Highlighted

Re: Unable to transfer data from Infotable to Stream

You can try something like this:

// tags:TAGS

var tags = new Array();

// timestamp:DATETIME

var timestamp = new Date();

for(var i=0; i<me.table.getRowCount(); i++){

    // values:INFOTABLE(Datashape: TestDS)

    var values = Things["testS"].CreateValues();

    values.value = me.table['value']; //INTEGER

    // location:LOCATION

    var location = new Object();

    location.latitude = 0;

    location.longitude = 0;

    location.elevation = 0;

    location.units ="WGS84";

    var params = {

        tags : tags,

        timestamp : timestamp,

        source : i,

        values : values,

        location : location

    };

    // AddStreamEntry(tags:TAGS, timestamp:DATETIME, source:STRING("me.name"), values:INFOTABLE(TestDS), location:LOCATION):NOTHING

    Things["testS"].AddStreamEntry(params);

}

You can see that i changed source to something special there, because I noticed, that if I left that property on default value I received only 1 record per Service test. This issue is associated with keeping data in Streams and creating Unique Keys for each record.

It is working for me.

BR,

Adam

Highlighted

Re: Unable to transfer data from Infotable to Stream

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);

}

Announcements

Thingworx Navigate content has a new home! Click here to access the new Thingworx Navigate forum! ______________________________