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

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

where can i get name of an infotable?

KSM
14-Alexandrite
14-Alexandrite

where can i get name of an infotable?

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.

5 REPLIES 5
vxavier
13-Aquamarine
(To:KSM)

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.

KSM
14-Alexandrite
14-Alexandrite
(To:vxavier)

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

vxavier
13-Aquamarine
(To:KSM)

 

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:

  1. Type SMTP.gmail.com in the SMTP Server field.
  2. Type 465 in the SMTP Server Port field.
  3. Type POP.gmail.com in the POP3 Server field.
  4. Type 995 in the POP3 Server Port field.
  5. Select the Use SSL check box.
  6. Type your Gmail e-mail address, in the Mail Account User field.
  7. Click the Change Password button.
  8. Type your Gmail password in the Enter New Password field.
  9. Type your Gmail password in the Retype Password field
  10. Click the Save button.

 

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.

 

 

KSM
14-Alexandrite
14-Alexandrite
(To:vxavier)

Thx a lot Xavier for great help,

 

I have not yet tried once I try then I will let you know.

slangley
23-Emerald II
(To:KSM)

Hi @KSM.

 

If the solution provided by @vxavier has answered your questions, please mark the appropriate reply as the Accepted Solution for the benefit of others with the same questions.

 

Regards.

 

--Sharon

Top Tags