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

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

Compare Thingworx infotable having same datashape

Siddharth_Jhs
14-Alexandrite

Compare Thingworx infotable having same datashape

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

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

@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);
}

 

View solution in original post

1 REPLY 1

@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);
}

 

Top Tags