Skip to main content
16-Pearl
August 12, 2024
Solved

How to find uncommon records in infotables without for loop.

  • August 12, 2024
  • 2 replies
  • 867 views

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?

 

 

Best answer by Rocko

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

 

 

2 replies

Rocko
Rocko19-TanzaniteAnswer
19-Tanzanite
August 13, 2024

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

 

 

12-Amethyst
November 11, 2024

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