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

Totaling valuestream - JSON does not allow non-finite numbers problem

SOLVED
Highlighted
Aquamarine

Totaling valuestream - JSON does not allow non-finite numbers problem

I`m going trough  valuestream entries and filtering them and saving to infotable in a service.

Basicaly im totalling values between hour A to hour B on each day for a week.

 

Problem is I get error when i use:

Totall+= StreamValue;

 

Im getting error:

"Wrapped org.json.JSONException: JSON does not allow non-finite numbers. Cause: JSON does not allow non-finite numbers."

 

everythign works fine if I use Totall+=1 or Totall= StreamValue;  but  +=StreamValue makes a problem.

 

Code used:

var params = {

                oldestFirst: undefined /* BOOLEAN */,

                maxItems: undefined /* NUMBER */,

                endDate: undefined /* DATETIME */,

                query: undefined /* QUERY */,

                startDate: undefined /* DATETIME */

};

var data = me.QueryPropertyHistory(params);

var params = {

                infoTableName : "InfoTable",

                dataShapeName : "StorageDataShape_granicd"

};

var result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);

var tableLength = data.rows.length;

 

var newEntry = new Object();

var Once=0;

for (var y = 0; y < 7; y++)

{

        var Type1=0;

        Once=0;

        newEntry.timestamp=null;

        for (var x = 0; x < tableLength; x++)

        {

            var row=data.getRow(x);

            if(row.timestamp.getDay()===y && row.timestamp.getHours() >= FromHour && row.timestamp.getHours() < TillHour) //row.timestamp.getDay()==y

            {

                if(Once==0)

                {

                    newEntry.timestamp=row.timestamp;

                    Once=1;

                }

                Type1+= row.LM;      //problem line      

          }

       }

       newEntry.LM_Totall=Type1;

       result.AddRow(newEntry);        

}

me.Totallhours=result;

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: Totaling valuestream - JSON does not allow non-finite numbers problem

Turns out problem was some properties in stream were NaN like error said(tho it refered to non-finite). I just needed to check in code first if they are NaN/empty then try to add them if they are not. :/ Best way is "if(x!=x)"  x - some property value.

View solution in original post

3 REPLIES 3
Highlighted

Re: Totaling valuestream - JSON does not allow non-finite numbers problem

Hello @DavorGranic,

 

Not sure exactly where the problem in the code could be, but I was thinking that this article might help:

https://www.ptc.com/en/support/article?n=CS267063 (refering to JSON not allowing non-finite numbers)

Highlighted

Re: Totaling valuestream - JSON does not allow non-finite numbers problem

Turns out problem was some properties in stream were NaN like error said(tho it refered to non-finite). I just needed to check in code first if they are NaN/empty then try to add them if they are not. :/ Best way is "if(x!=x)"  x - some property value.

View solution in original post

Highlighted

Re: Totaling valuestream - JSON does not allow non-finite numbers problem

Hi @DavorGranic.

 

If you are satisfied with the solution you posted, please mark it as the Accepted Solution for the benefit of others with the same question.

 

Thank you for using our Community!

 

Regards.

 

--Sharon

Announcements

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