Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X
I am using one infotable function, to json , in code snippet there we need to define infotable, am confusing where should I get this name of infotable.
You have to create the infotable, by code, or set it as input.
To set it as input you need to create a Data Shape first with the fields. Then you select infotable as input and then select your Data Shape.
To use it in code you can create from zero using the snippet function Create empty JSONObject InfoTable:
var nameOfyourInfotable = { dataShape: { fieldDefinitions : {} }, rows: [] };
or you can create also by a Data Shape, by selecting the snippet Create Infotable from datashape, it will ask you to select a Data Shape with the field definitions that you want for your infotable:
var params = { infoTableName : "your info table name", dataShapeName : "your data shape name" }; // CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(your data shape name) var infoTableName = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);
Cheers,
Vinicius.
Thanks for your reply,
actual my requirement is that I have selected some rows in grid and then click one button, after clicking the button one model pop window will open with selected rows on the grid. that data i need to send to email of the user . so that i need to create one service in that service i want to extract that selected rows data and insert into the body of the mail. any ideas or any documents on this extracting the grid data and parsing and etc..
To send the e-mail you will need the extension: Mail Extension.
After installing the extension you will need to create a thing and pass the Mail Server as the Template of the thing.
Then you go for the Configuration tab, This example is configuring to work with gmail SMTP server with SSL:
Now you can create your Service,
You define the input of your service as an infotable, this infotable will have the fields names of the table of your selected rows.
To get the rows information you use a Snippet called "Infotable for loop",
var tableLength = yourInfotableHere.rows.length; for (var x=0; x < tableLength; x++) { var row = yourInfotableHere.rows[x]; //Your code here }
then, to get the data of the fields of the table to send to the e-mail you use row.yourFieldName or row["yourFieldName"].
The body of the e-mail is an html, you have to create the table as html.
Here you have a tutorial how construct and style tables with html: https://www.w3schools.com/html/html_tables.asp
The complete code that I did was this:
//Your infotable number of rows
var tableLength = myInfotable.rows.length;
//Your infotable number of fields, myInfotable should be the input of your service,
//with the data-shape that defines your SelectedRows. var numberOfFields = myInfotable.dataShape.fields.length;
//Creating your html variable var html = "<table><tr>"; // infotable datashape iteration, here we set the first row of the table with yours field-names. var dataShapeFields = myInfotable.dataShape.fields; for (var fieldName in dataShapeFields) { html += "<th>" + dataShapeFields[fieldName].name + "</th>"; } html += "</tr>"; //In this last for loop iterate in the rows and columns and add your data to the html table for (var x=0; x < tableLength; x++) { var row = myInfotable.rows[x]; html += "<tr>"; for (fieldName in dataShapeFields) { html += "<td>" + row[dataShapeFields[fieldName].name] + "</td>"; } html += "</tr>"; }
//closing the table html += "</table>";
//Sending the e-mail me.SendMessage({ cc: undefined /* STRING */, bcc: undefined /* STRING */, subject: "My Teste e-mail Table" /* STRING */, from: "yourgmail@gmail.com" /* STRING */, to: "somemail@mail.com" /* STRING */, body: html /* HTML */ });
Hope it helps,
Vinícius Xavier.
Thx a lot Xavier for great help,
I have not yet tried once I try then I will let you know.