2 Replies Latest reply on Sep 13, 2015 10:35 PM by anna RSS
    anna Creator

    How to read a infotable or DataTable to a JSON in Thingworx?

    we have data stored in DataTable or we create a service which will return an InfoTable, and then we want to export these data into a JSON file, how to do that?

      • Re: How to read a infotable or DataTable to a JSON in Thingworx?
        saeedma Apprentice

        This can be done by creating a service that uses the SaveJSON() snippet to save the content of a dataTable or Infotable to a file repository. You can use GetFileListingWithLinks() to return a download link to the file in the repository. This link can be bound to a link widget in a mashup.

         

        The code below is on a file repository thing and creates a folder in the root of the repository folder in Thingworx storage, then gets the datatable entries for the desired table. This table is then set to the content of the SaveJSON service and finally calls GetFileListingWithLinks to return a download link to the file.

         

        var params = {

          path: "/" /* STRING */

        };

        me.CreateFolder(params);

         

         

        var params = {

          maxItems: undefined /* NUMBER */

        };

        //result: INFOTABLE dataShape: "undefined"

        var table = Things["test"].GetDataTableEntries(params);

         

        var params = {

          path: "/TestJSON" /* STRING */,

          content: table /* JSON */

        };

        me.SaveJSON(params);

         

        var params = {

          path: "/" /* STRING */,

          nameMask: undefined /* STRING */

        };

        // result: INFOTABLE dataShape: "FileSystemFileWithLinks"

        var result = me.GetFileListingWithLinks(params);

        • Re: How to read a infotable or DataTable to a JSON in Thingworx?
          anna Creator

          Hi Saeed,

          It works. Thanks a lot!

           

          Br,

          Anna