6 Replies Latest reply on Mar 15, 2017 11:40 AM by adamr RSS
    mvolanti Apprentice

    Unable to transfer data from Infotable to Stream


    I want to transfer data from Infotable to  a Stream.


    I tried this:





    Thingame = "THGF_LPIPPO1";   



    var grid = Things[Thingame].Cont_Grid;




    var length  = grid.rows.length;



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


            var row = grid.rows[j];



           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







    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



    but I have the following error:


    Wrapped java.lang.NullPointerException Cause: null



    Can you help me???








    Thingworx: 7.2.6 

      • Re: Unable to transfer data from Infotable to Stream
        polinao Ninja

        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
            mvolanti Apprentice

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

              • Re: Unable to transfer data from Infotable to Stream
                Adam Macierzyński Explorer

                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.



                Best Regards,


                  • Re: Unable to transfer data from Infotable to Stream
                    mvolanti Apprentice

                    Is correct.


                    if you try:


                    var length  = grid.rows.length;





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


                    Can you try my code to transfer infotable to stram?



                      • Re: Unable to transfer data from Infotable to Stream
                        Adam Macierzyński Explorer

                        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[i]['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



                        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.



                • Re: Unable to transfer data from Infotable to Stream
                  adamr Creator

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