Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X
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);
}
}
Solved! Go to Solution.
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);
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);
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!