2 Replies Latest reply on Oct 21, 2015 4:22 PM by ryankelley RSS
    byutz Apprentice

    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.

      • Re: How to return a small datatable
        carlesc Ninja

        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.