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

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

DataTable query not working

Willie
16-Pearl

DataTable query not working

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)]"

ACCEPTED SOLUTION

Accepted Solutions
Willie
16-Pearl
(To:Willie)

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.

View solution in original post

2 REPLIES 2
posipova
20-Turquoise
(To:Willie)

Have you tried setting the output to Infotable?

Willie
16-Pearl
(To:Willie)

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.

Announcements


Top Tags