5 Replies Latest reply on Jan 14, 2018 5:15 PM by msilva RSS
    msilva Newbie

    Java: InfoTable addRow of ValueCollection puts empty



    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(" InfoTable: " + infoTable.toJSON().toString());





    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.


      • 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)));
        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.