3 Replies Latest reply on Jan 26, 2017 3:21 PM by jkaczynski-2 RSS
    msilva 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):

     

         [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(...);

         [/code]

     

    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

      • Re: Java: InfoTable addRow of ValueCollection puts empty
        jkaczynski-2 Creator

        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.