Skip to main content
6-Contributor
July 11, 2022
Question

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

  • July 11, 2022
  • 1 reply
  • 857 views

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

22-Sapphire I
July 11, 2022

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?