Skip to main content
1-Visitor
October 19, 2015
Solved

How to return a small datatable

  • October 19, 2015
  • 1 reply
  • 2168 views

I have several small calculations that I would like to do.  I can easily write a service for each of them and return an single value.  I would like to have one service and just return a datatable of all of these values.  Does anyone have an example on how to do this?  I have found a few snippets of code, but I can't seem to get the syntax correct.  Thanks!

P.S. Did the Correct Answer button disappear with the forum update?  I don't see it anymore.

Best answer by CarlesColl

Create a DataShape with the fields that you want to return, let's name it MyShape, which has two fields: columnName1, columnName2.

Then create a new service which should look like:

var value1 = me.ServiceCalculation1();

var value2 = me.ServiceCalculation2();

var result =  Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({

          infoTableName: "InfoTable",

          dataShapeName: "MyShape"

});

result.AddRow({

    columnName1: value1,

    columnName2: value2

});

Of course the Return Value for this service should be InfoTable with DataShape: MyShape.

1 reply

1-Visitor
October 19, 2015

Create a DataShape with the fields that you want to return, let's name it MyShape, which has two fields: columnName1, columnName2.

Then create a new service which should look like:

var value1 = me.ServiceCalculation1();

var value2 = me.ServiceCalculation2();

var result =  Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({

          infoTableName: "InfoTable",

          dataShapeName: "MyShape"

});

result.AddRow({

    columnName1: value1,

    columnName2: value2

});

Of course the Return Value for this service should be InfoTable with DataShape: MyShape.

1-Visitor
October 21, 2015

byutz - just wanted to confirm you were able to find the correct button. Let me know if you have any other questions about the ThingWorx Community​ upgrade over at the Community Hub​.