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

Community email notifications are disrupted. While we are working to resolve, please check on your favorite boards regularly to keep up with your conversations and new topics.

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

BK_10290693
5-Regular Member

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?

Top Tags