Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X
Hello,
I'm trying to pass an InfoTable as argument/parameter to a service at ThingWorx platform. All service calls work just fine but the InfoTable goes empty.
I'm populating the InfoTable this way (pseudo code):
InfoTable infoTable = new InfoTable();
ValueCollection definitions = new ValueCollection();
FOR (<# of properties>) {
definitions.put(Definition.name, new <T>Primitive(value-1));
...
definitions.put(Definition.name, new <T>Primitive(value-n));
log.debug(definitions.toJSON().toString());
infoTable.addRow(definitions.clone());
}
log.debug(" InfoTable: " + infoTable.toJSON().toString());
client.invokeService(...);
Now all this comes to output:
{..., "baseType":"<type>","description":"<desc>","name":"<name>", ... }
InfoTable: {"dataShape":{"fieldDefinitions":{}},"rows":[{},{},{},{}]}
Basically, an InfoTable object with empty value collections (the right amount of times, at least ).
What am I doing wrong or making a wrong assumption on how to populate an InfoTable?
Much appreciated for everyone that is able to contribute.
Cheers
Solved! Go to Solution.
Hi Marco Silva,
Don't know if it's just because of short version of pseudocode, but I see that you create an empty InfoTable with no field definitions specified.
Using this way, Thingworx unfortunately doesn't send the data to Thingworx service. Below you can find working sample:
DataShapeDefinition dsd = new DataShapeDefinition();
dsd.addFieldDefinition(new FieldDefinition("field1", "NUMBER"));
dsd.addFieldDefinition(new FieldDefinition("field2", "NUMBER"));
dsd.addFieldDefinition(new FieldDefinition("field3", "NUMBER"));
InfoTable it = new InfoTable(dsd);
ValueCollection row = new ValueCollection();
Random rnd = new Random();
for(int i = 0; i < 5; i++) {
row.SetNumberValue("field1", new NumberPrimitive(rnd.nextInt(100)));
row.SetNumberValue("field2", new NumberPrimitive(rnd.nextInt(100)));
row.SetNumberValue("field3", new NumberPrimitive(rnd.nextInt(100)));
it.addRow(row.clone());
}
ValueCollection params = new ValueCollection();
params.SetInfoTableValue("ServiceITParameterName", prop); // my service had just one parameter of type InfoTable
client.invokeService(ThingworxEntityTypes.Things, "ThingName", "ServiceName", params, 1500);
Hope it helps, don't hesitate to ask if something is not clear.
Regards,
Jakub.
Hi Marco Silva,
Don't know if it's just because of short version of pseudocode, but I see that you create an empty InfoTable with no field definitions specified.
Using this way, Thingworx unfortunately doesn't send the data to Thingworx service. Below you can find working sample:
DataShapeDefinition dsd = new DataShapeDefinition();
dsd.addFieldDefinition(new FieldDefinition("field1", "NUMBER"));
dsd.addFieldDefinition(new FieldDefinition("field2", "NUMBER"));
dsd.addFieldDefinition(new FieldDefinition("field3", "NUMBER"));
InfoTable it = new InfoTable(dsd);
ValueCollection row = new ValueCollection();
Random rnd = new Random();
for(int i = 0; i < 5; i++) {
row.SetNumberValue("field1", new NumberPrimitive(rnd.nextInt(100)));
row.SetNumberValue("field2", new NumberPrimitive(rnd.nextInt(100)));
row.SetNumberValue("field3", new NumberPrimitive(rnd.nextInt(100)));
it.addRow(row.clone());
}
ValueCollection params = new ValueCollection();
params.SetInfoTableValue("ServiceITParameterName", prop); // my service had just one parameter of type InfoTable
client.invokeService(ThingworxEntityTypes.Things, "ThingName", "ServiceName", params, 1500);
Hope it helps, don't hesitate to ask if something is not clear.
Regards,
Jakub.
Right you are Jakub Kaczynski!
I wasn't making the DataShape definition hence the InfoTable was appearing totally blank.
That was the issue
Manythanks!
You're welcome, always glad to help
Regards,
J.
I had a similar issue, but this time it's the ValueCollection object which when I add value into it with put method, it will put nothing finally. See my test code:
@ThingworxServiceDefinition( name="SayHello", description="Hello world" ) |
@ThingworxServiceResult( name="Result", description="Result", baseType="STRING" )
public String SayHello() throws Exception {
ValueCollection values = new ValueCollection(); | |
values.put("name", new StringPrimitive("prop1")); | |
values.put("value", new StringPrimitive("hello")); | |
values.put("quality", new StringPrimitive("GOOD")); | |
System.out.println(values); | |
return values.get("value").getStringValue(); |
}
but it will print out
{name=null, value=null, quality=null}
It seems the value is not set successfully into ValueCollection at all; currently I am using Extension SDK 7.4.0, and we have the same issue on 7.1.0.
Did you guys have the same issue?
Thanks,
Br,
Anna
Hello Anna An,
Please refer to my snipped included in one of the previous posts. You should use .SetXXXValue(...), e.g. SetStringValue(...) method instead. Put is not the right one.
Please let me know if it fixes your issue.
Regards,
J.