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

How to find uncommon records in infotables without for loop.

AP_10343008
15-Moonstone

How to find uncommon records in infotables without for loop.

I have infotable A and infotable B.

Ill compare data in both infotable A and infotable B.

Ill delete the matched records in both tables and the uncommon records remains in both the tables infotable A and infotable B.

How it can be done without using for loop?

Any infotable functions will be helpful?

 

 

ACCEPTED SOLUTION

Accepted Solutions

Even if you wouldn't use a for loop, one would have to be used internally, so it doesn't make a difference. You can't do this without iterating the values.

TBH instead of altering the infotables I would just create new ones. This is how you could compute A minus B, assuming you compare on column age.

If you need to compare every property, it's more complex.

 

let result = Resources["InfoTableFunctions"].CreateInfoTable();
result.AddField({name:"id", baseType:"STRING"});
result.AddField({name:"name", baseType:"STRING"});
result.AddField({name:"age", baseType:"INTEGER"});

let deleteTable = Resources["InfoTableFunctions"].Clone({t1:result});
let resultTable = Resources["InfoTableFunctions"].Clone({t1:result});

result.AddRow({id:"4",name:"A",age:10});
result.AddRow({id:"5",name:"B",age:20});
result.AddRow({id:"6",name:"C",age:30});
result.AddRow({id:"7",name:"D",age:40});

deleteTable.AddRow({id:"6",name:"C",age:30});
deleteTable.AddRow({id:"7",name:"D",age:40});
deleteTable.AddRow({id:"8",name:"E",age:50});

// until here it's just setting up some data. result would be Table A, deleteTable would be Table B

let delArray=deleteTable.rows.toArray().map(r=>r.id);
result.rows.toArray().forEach(row=>{ if (!delArray.includes(row.id)) resultTable.AddRow(row);});

result=resultTable; // A minus B, now repeat to do B minus A

 

 

View solution in original post

2 REPLIES 2

Even if you wouldn't use a for loop, one would have to be used internally, so it doesn't make a difference. You can't do this without iterating the values.

TBH instead of altering the infotables I would just create new ones. This is how you could compute A minus B, assuming you compare on column age.

If you need to compare every property, it's more complex.

 

let result = Resources["InfoTableFunctions"].CreateInfoTable();
result.AddField({name:"id", baseType:"STRING"});
result.AddField({name:"name", baseType:"STRING"});
result.AddField({name:"age", baseType:"INTEGER"});

let deleteTable = Resources["InfoTableFunctions"].Clone({t1:result});
let resultTable = Resources["InfoTableFunctions"].Clone({t1:result});

result.AddRow({id:"4",name:"A",age:10});
result.AddRow({id:"5",name:"B",age:20});
result.AddRow({id:"6",name:"C",age:30});
result.AddRow({id:"7",name:"D",age:40});

deleteTable.AddRow({id:"6",name:"C",age:30});
deleteTable.AddRow({id:"7",name:"D",age:40});
deleteTable.AddRow({id:"8",name:"E",age:50});

// until here it's just setting up some data. result would be Table A, deleteTable would be Table B

let delArray=deleteTable.rows.toArray().map(r=>r.id);
result.rows.toArray().forEach(row=>{ if (!delArray.includes(row.id)) resultTable.AddRow(row);});

result=resultTable; // A minus B, now repeat to do B minus A

 

 

Hi @AP_10343008

It appears that a response to this post answers your question. For the benefit of other Community Members who may have the same question, it would be great if you could designate it as the Accepted Solution.

In the event that this response did not answer your question, please post your current status so that we can continue to support.

Thanks for using the PTC Community!

Regards,
Abhi

Announcements


Top Tags