Skip to main content
16-Pearl
January 15, 2020
Solved

Using infotable

  • January 15, 2020
  • 1 reply
  • 3593 views
Hi ,
I want to know how many ways we can create infotable and which one is preferable. And how to manipulate infotable data in other things and use its field value.

Thank you
Best answer by rosharma

let's suppose infotable results from datatable is somwhat like id =1 and name = "rohit"

will change this name from rohit to rohit_sharma and add it back to empty infotable.

 

below is the snippet for this

 

// result: INFOTABLE dataShape: ""

// getting all infotable entries from datatable
var old_infotableresult = Things["infotableTestDT"].GetDataTableEntries({
maxItems: undefined /* NUMBER */
});

// creating an empty infotable using the datashape

var params = {
infoTableName : "InfoTable",
dataShapeName : "infotableTestDS"
};

// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(infotableTestDS)
var result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);

 

 

// looping out old infotable and updating the required row and again adding the entry to empty new infotable created

var tableLength = old_infotableresult.rows.length;
for (var x=0; x < tableLength; x++) {
var row = old_infotableresult.rows[x];
//Your code here
// infotableTestDS entry object
if(row.id == "1"){
row.name = "rohit_sharma"; // changing from rohit to rohit_sharma
}
var newEntry = new Object();
newEntry.name = row.name; // STRING
newEntry.id = row.id; // STRING [Primary Key]

result.AddRow(newEntry);


}

// in this way result infotable will be returned with updated row while other rows will be returned same as what it used to be 

 

1 reply

16-Pearl
January 16, 2020

you can create infotable through snippets available in platform like createInfotable or create infotable from datashape or by using clone methods.

many snippets available for manipulation and creation as well under services -- > snippets -- > infotablefunctions

 

generally for manipulations your infotable will have datashape assigned to it. use available for loops to iterate through infotable , get values and do calculations.

to set the values to infotable, you need to create infotable entry using datashape using snippets "create infotable entry from datashape" , set values to all fields and then use AddRow(object) snippet to add the entry to infotable.

 

overall all snippets are available in infotablefunctions ( snippets tab on service window)

16-Pearl
January 19, 2020
Hello rosharma,
Thank you for your reply but
Suppose i have to update or add a name field value whose id is 1. Then how it should be done in jnfotable.
Please reply for this
Thank you
rosharma16-PearlAnswer
16-Pearl
January 20, 2020

let's suppose infotable results from datatable is somwhat like id =1 and name = "rohit"

will change this name from rohit to rohit_sharma and add it back to empty infotable.

 

below is the snippet for this

 

// result: INFOTABLE dataShape: ""

// getting all infotable entries from datatable
var old_infotableresult = Things["infotableTestDT"].GetDataTableEntries({
maxItems: undefined /* NUMBER */
});

// creating an empty infotable using the datashape

var params = {
infoTableName : "InfoTable",
dataShapeName : "infotableTestDS"
};

// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(infotableTestDS)
var result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(params);

 

 

// looping out old infotable and updating the required row and again adding the entry to empty new infotable created

var tableLength = old_infotableresult.rows.length;
for (var x=0; x < tableLength; x++) {
var row = old_infotableresult.rows[x];
//Your code here
// infotableTestDS entry object
if(row.id == "1"){
row.name = "rohit_sharma"; // changing from rohit to rohit_sharma
}
var newEntry = new Object();
newEntry.name = row.name; // STRING
newEntry.id = row.id; // STRING [Primary Key]

result.AddRow(newEntry);


}

// in this way result infotable will be returned with updated row while other rows will be returned same as what it used to be