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

Java: InfoTable addRow of ValueCollection puts empty

SOLVED
Highlighted
Newbie

Java: InfoTable addRow of ValueCollection puts empty

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

Tags (2)
1 ACCEPTED SOLUTION

Accepted Solutions

Re: Java: InfoTable addRow of ValueCollection puts empty

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.

5 REPLIES 5

Re: Java: InfoTable addRow of ValueCollection puts empty

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.

Re: Java: InfoTable addRow of ValueCollection puts empty

Right you are Jakub Kaczynski​!

I wasn't making the DataShape definition hence the InfoTable was appearing totally blank.

That was the issue

Manythanks!

Re: Java: InfoTable addRow of ValueCollection puts empty

You're welcome, always glad to help

Regards,

J.

Re: Java: InfoTable addRow of ValueCollection puts empty

Jakub Kaczynski​,

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

Re: Java: InfoTable addRow of ValueCollection puts empty

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.