I keep getting a type error when trying to query a DataTable.
Please see my code below:
******************************************************
var params = {
NameOfOrgUnit: UserSelectedOrgUnit /* STRING */
};
//base type of nameOfDataTable is THINGNAME
var nameOfDataTable = me.getDataTableNameBasedOnOrgUnit(params);
var query = {
"filters": {
"fieldName": "customerName",
"type": "EQ",
"value": UserInputCustomerName //STRING
}
};
var params = {
maxItems: undefined /* NUMBER */,
values: undefined /* INFOTABLE*/,
query: query /* QUERY */,
source: undefined /* STRING */,
tags: undefined /* TAGS */
};
// result: INFOTABLE dataShape: "undefined"
var result = nameOfDataTable.QueryDataTableEntries(params);
**********************************************************
I've tried setting the output of the service DataTableNameBasedOnOrgUnit to STRING and THINGNAME; however, I keep getting a script error that says the following:
if output is STRING: "[message: Execution error in service script [checkIfCustomerNameExists] :: TypeError: Cannot find function QueryDataTableEntries in object SFG.Customer.Norway.DT. (checkIfCustomerNameExists#25)]"
if output is THINGNAME: "[message: Execution error in service script [checkIfCustomerNameExists] :: TypeError: Cannot call method "QueryDataTableEntries" of null (checkIfCustomerNameExists#25)]"
Solved! Go to Solution.
I was able to resolve the issue by changing the last line.
Before: var result = nameOfDataTable.QueryDataTableEntries(params);
After: var result = Things[nameOfDataTable].QueryDataTableEntries(params);
It also doesn't matter if the base type is STRING or THINGNAME in my getDataTableNameBasedOnOrgUnit service output. It works either way.
Have you tried setting the output to Infotable?
I was able to resolve the issue by changing the last line.
Before: var result = nameOfDataTable.QueryDataTableEntries(params);
After: var result = Things[nameOfDataTable].QueryDataTableEntries(params);
It also doesn't matter if the base type is STRING or THINGNAME in my getDataTableNameBasedOnOrgUnit service output. It works either way.