Skip to main content
14-Alexandrite
June 24, 2022
Solved

Compare Thingworx infotable having same datashape

  • June 24, 2022
  • 1 reply
  • 1330 views

I have 2 infotables with same datashape. I need to compare them and store the difference in third infotable.

For example,

DifferenceTable.Reading = CurrentTable.Reading - PreviousTable.Reading

where Reading is a property name for all 3 tables.

Kindly provide solution for same.

 

Regards,

Siddharth

 

 

 

Best answer by nmilleson

@Siddharth_Jhs ,

 

The easiest way to do this is to just iterate through the infotables and compare the columns one-by-one and then store the differences in a third infotable.

 

For example, if you know that the rows in the first two tables should be directly compared (i.e. you want to compare row 1 of the first table with row 2 of the second table: 

var len = myInfoTable1.getRowCount()


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

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


for(var i = 0; i < len; i++) {
 var diff1 = myInfoTable2[i].Reading - myInfoTable1[i].Reading;
 var diff2 = myInfoTable2[i].AnotherReading - myInfoTable1[i].AnotherReading;
 
 var row = new Object();
 
 row.Reading = diff1;
 row.AnotherReading = diff2;
 
 result.AddRow(row);
}

 

1 reply

nmilleson17-PeridotAnswer
17-Peridot
June 27, 2022

@Siddharth_Jhs ,

 

The easiest way to do this is to just iterate through the infotables and compare the columns one-by-one and then store the differences in a third infotable.

 

For example, if you know that the rows in the first two tables should be directly compared (i.e. you want to compare row 1 of the first table with row 2 of the second table: 

var len = myInfoTable1.getRowCount()


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

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


for(var i = 0; i < len; i++) {
 var diff1 = myInfoTable2[i].Reading - myInfoTable1[i].Reading;
 var diff2 = myInfoTable2[i].AnotherReading - myInfoTable1[i].AnotherReading;
 
 var row = new Object();
 
 row.Reading = diff1;
 row.AnotherReading = diff2;
 
 result.AddRow(row);
}