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

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

How to return a small datatable

byutz
12-Amethyst

How to return a small datatable

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.

ACCEPTED SOLUTION

Accepted Solutions

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.

View solution in original post

2 REPLIES 2

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.

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​.

Announcements


Top Tags