Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X
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?
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);
Hi Saeed,
It works. Thanks a lot!
Br,
Anna