Skip to main content
16-Pearl
July 25, 2024
Solved

how to collect data entries from three datatable

  • July 25, 2024
  • 1 reply
  • 1636 views

Hey Community, here i want data from three different datatables and i want to have all the entries in one infotable. How can i achieve it? i think i need to have here infotable and collect all the data there...

 

let data;
linesArray.forEach(line => {
 
 logger.info("QControl."+line.lineName+"-"+line.lineLocation+".DT");
 let thingName = "QControl."+line.lineName+"-"+line.lineLocation+".DT";
 let maxItems = Things[thingName].GetDataTableEntryCount();
 data = Things[thingName].GetDataTableEntries({
 maxItems: maxItems /* NUMBER */
 });

}); 

 

Best answer by Velkumar

Hi @MA8731174 

 

Instead of iteration over each row of data. You can use below code merge multiple tables

 

function mergeTables(table1, table2) {
	let params = {
		t1: table1 /* INFOTABLE */ ,
		t2: table2 /* INFOTABLE */
	};

	// result: INFOTABLE
	let mergedTable = Resources["InfoTableFunctions"].Union(params);
	return mergedTable;
}

function getTableData(dataTableName) {
	let dataTableData = Things[dataTableName].GetDataTableEntries({
		maxItems: maxItems /* NUMBER */
	});
	return dataTableData;
}

let tableNames = ["Table1", "Table2", "Table3"];
let result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
	infoTableName: "InfoTable",
	dataShapeName: "DATASHAPENAME"
});

tableNames.forEach((tableName) => {
	let tableData = getTableData(tableName);
	result = mergeTables(result, tableData);
});

 

/VR

 

 

1 reply

MA873117416-PearlAuthor
16-Pearl
July 25, 2024

I am doing like this so first flateneing the entries and saving them into an infotable. I hope that it will not lower the performance. Or is there any better solution as compared to this one.

let CollectAllEntriesIntoTable = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
 infoTableName: "InfoTable",
 dataShapeName: "QControl.QualityData.DS"
});



let data;
linesArray.forEach(line => {
 
 logger.info("QControl."+line.lineName+"-"+line.lineLocation+".DT");
 let thingName = "QControl."+line.lineName+"-"+line.lineLocation+".DT";
 let maxItems = Things[thingName].GetDataTableEntryCount();
 data = Things[thingName].GetDataTableEntries({
 maxItems: maxItems /* NUMBER */
 });
 data.rows.forEach(entry=>{
 CollectAllEntriesIntoTable.AddRow(entry);
 });


}); 

 

 

19-Tanzanite
July 25, 2024

Hi @MA8731174 

 

If all there datatable has same DataShape. You can use union function to merge it

 

let params = {
	t1: table1 /* INFOTABLE */,
	t2: table2 /* INFOTABLE */
};

// result: INFOTABLE
let result = Resources["InfoTableFunctions"].Union(params);

 

/VR

MA873117416-PearlAuthor
16-Pearl
July 25, 2024

Thanks @Velkumar ..They have all the same datashapes but i have total 7 datatables and may be they will grow in future so the approached you have mentioned would not bad but does not fit here. Thats why i am now iterating each entry to store it in an infotable.