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

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

How to read sql query data in a thingworx local javascript service

BK_10290693
6-Contributor

How to read sql query data in a thingworx local javascript service

I am trying to call the sql query service in a javascript service. While printing the length of the data returned from the sql query, it is giving null.

While executing the local service, it is throwing error: Error executing service. Message ::Unable To Convert From org.mozilla.javascript.UniqueTag to INFOTABLE - See Script Error Log for more details.

 

Can anyone please tell me where am I going wrong.

 

try {
  let sqlData = me.getAllProductsDetails_DB;
  logger.info("mySQL_DB_TH   getAllProductsDetails  sqldata" + sqlData.length); // Output is null

  // CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(AllProducts_DS)
  let data = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
    infoTableName: "InfoTable",
    dataShapeName: "AllProducts_DS",
  });

  for (var i = 0; i < sqlData.length; i++) {
    var row = sqlData.getRow(i);

    // AllProducts_DS entry object
    let newEntry = {
      productsId: row.productsId, // INTEGER
      name: row.name, // STRING
      description: row.description, // STRING
      dateofpurchase: row.dateofpurchase, // DATETIME
      productImage: row.productImage, // STRING
      category: row.category, // STRING
      gender: row.gender, // STRING
      brand: row.brand, // STRING
    };
    data.AddRow(newEntry);

    result = data;
  }
} catch (err) {
  logger.error(
    "mySQL_DB_TH - getAllProductsDetails : " + err.message + " at line Number : " + err.lineNumber
  );
}
1 REPLY 1
PaiChung
22-Sapphire I
(To:BK_10290693)

It looks like your first service is already returning an infotable? Why iterate it again to build another table?

What is your Service Output set to?

Announcements


Top Tags