Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X
I'm trying to create InfoTable in Java, but it's always empty. What do I do wrong?
Created "ThingWorx Extension Project" in Eclipse 2022-03 with "ThingWorx Eclipse Plugin 9.0.1" installed, using SDK 9.2.0, Gradle 6.9.1 and Amazon Corretto 11.0.10.
public static void main(String[] args) throws Exception {
// Create InfoTable
DataShapeDefinition ds = new DataShapeDefinition();
ds.addFieldDefinition(new FieldDefinition("field1", BaseTypes.NUMBER));
InfoTable table = new InfoTable(ds);
ValueCollection row = new ValueCollection();
row.SetNumberValue("field1", 1);
table.addRow(row.clone());
}
Also, tried `new InfoTableFunctions().FromJSON(myJsonInfoTable)` and it doesn't work too.
// Create InfoTable from JSON
JSONObject infoTableJson = new JSONObject("{\"dataShape\":{\"fieldDefinitions\":{\"id\":{\"name\":\"id\",\"description\":\"id\",\"baseType\":\"STRING\"}}},\"rows\":[{\"id\":\"someString\"}]}");
InfoTableFunctions fns = new InfoTableFunctions();
InfoTable table = fns.FromJSON(infoTableJson);
Solved! Go to Solution.
You are not able to execute/test your logic without having it deployed in ThingWorx. If you deploy the extension you should see the result (if it works - I did not check the code).
The extensionSDK just has Dummy implementations - so Infotable.addRow(x) has no implementation. As well as toJson has {return null} as implementation. It just does nothing. A real pain for (unit)testing anything. If deployed in the platform the real implementation will be used.
(That was the state when I last checked it more than 1 year ago)
You can reproduce it.
I downloaded your completed "MyThingworxWeatherExtension" example ExtensionSampleFiles.zip from this tutorial Create An Extension.
I'm still getting an empty InfoTable.
Added new class InfoTableCreator with the code below:
package com.thingworx.weather;
import com.thingworx.metadata.DataShapeDefinition;
import com.thingworx.metadata.FieldDefinition;
import com.thingworx.types.BaseTypes;
import com.thingworx.types.InfoTable;
import com.thingworx.types.collections.ValueCollection;
public class InfoTableCreator {
public static void main(String[] args) throws Exception {
// Create InfoTable
InfoTable table1 = createInfoTable();
// => null
System.out.println(table1.toJSON());
}
public static InfoTable createInfoTable() throws Exception {
DataShapeDefinition ds = new DataShapeDefinition();
ds.addFieldDefinition(new FieldDefinition("field1", BaseTypes.NUMBER));
InfoTable table = new InfoTable(ds);
ValueCollection row = new ValueCollection();
row.SetNumberValue("field1", 1);
table.addRow(row);
return table;
}
}
You are not able to execute/test your logic without having it deployed in ThingWorx. If you deploy the extension you should see the result (if it works - I did not check the code).
The extensionSDK just has Dummy implementations - so Infotable.addRow(x) has no implementation. As well as toJson has {return null} as implementation. It just does nothing. A real pain for (unit)testing anything. If deployed in the platform the real implementation will be used.
(That was the state when I last checked it more than 1 year ago)
@nmutter wrote:A real pain for (unit)testing anything.
Exactly.
BTW It's possible to create InfoTables using Edge SDK (not Extensions SDK).