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

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

union of two infotables causing "null point exception"

lhui
3-Newcomer

union of two infotables causing "null point exception"

Hi all,

I'm trying to union two infotables in my service but get a "Wrapped java.lang.NullPointerException Cause: null" error when I do. In my service I want to run a single query a variable number of times with a changes in 1 input parameter and then union them together. I do not seem to be able to do it. The infotable columns are exactly the same since the results are coming from the same query. I have it in a forloop so that I can append it a few times depending on how many instrument types the user selects.

How do I get this to work?

thanks!

code below:

    var rawData1;

    var rawDataA; var rawDataB;

    var instrumentType;

   

for each (var row in InstrumentTypes.rows){

    

        instrumentType = row.StringField;

    var instrumentType1;

        

switch(instrumentType){

case "1":

instrumentType1 = "A"

            

                var params = {

                    StartDate: sdate /* DATE */,

                    EndDate: edate /* DATE */,

                    ShowExternalRunsOnly: showExternalRuns /* BOOLEAN */,

                    InstrumentType1: instrumentType1 /*STRING*/,

                };

                rawDataA = Things["RedShiftDatabase"].CustomQueryAllPlatformsDataQueryv3(params);

            

break;

            case "2":

instrumentType1 = "B"

                logger.error("instrumentType1: " + instrumentType1);

            

                var params = {

                    StartDate: sdate /* DATE */,

                    EndDate: edate /* DATE */,

                    ShowExternalRunsOnly: showExternalRuns /* BOOLEAN */,

                    InstrumentType1: instrumentType1 /*STRING*/,

                };

                rawDataA = Things["RedShiftDatabase"].CustomQueryAllPlatformsDataQueryv3(params);            

                break;

    

}  

            // Union tables from switch *UNION NOT WORKING FROM DIFFERENT INFOTABLES*

            var params = {

                t1: rawData1, // INFOTABLE

                t2: rawDataA // INFOTABLE

            };

            // result: INFOTABLE

            rawData1 = Resources["InfoTableFunctions"].Union(params);         

    

        }

}

ACCEPTED SOLUTION

Accepted Solutions

Lawrence,

Is this the exact code you are using.?

The first question I might ask myself could  rawData1 or rawData2  be null if the case statement does not find anything match?

I would create empty infotables for rawData1 and rawData1 to protect my code against null values

for example I usually place this at the top of my code for any infotables -  if I expect an InfoTable to be returned

var dataShapeName = "MY DATASHAPE";

//create empty table in case nothing found

var params = {

            infoTableName: "Values",

            dataShapeName: dataShapeName

        };

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

View solution in original post

2 REPLIES 2

Lawrence,

Is this the exact code you are using.?

The first question I might ask myself could  rawData1 or rawData2  be null if the case statement does not find anything match?

I would create empty infotables for rawData1 and rawData1 to protect my code against null values

for example I usually place this at the top of my code for any infotables -  if I expect an InfoTable to be returned

var dataShapeName = "MY DATASHAPE";

//create empty table in case nothing found

var params = {

            infoTableName: "Values",

            dataShapeName: dataShapeName

        };

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

lhui
3-Newcomer
(To:lhui)

That's exactly what I was missing. Setting up a datashape so that I could union my answers together even if some of them were null. Thanks Steve!

Announcements


Top Tags