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

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

how to collect data entries from three datatable

MA8731174
14-Alexandrite

how to collect data entries from three datatable

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 */
    });

});  

 

ACCEPTED SOLUTION

Accepted Solutions

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

 

 

View solution in original post

4 REPLIES 4
MA8731174
14-Alexandrite
(To:MA8731174)

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


});  

 

 

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

MA8731174
14-Alexandrite
(To:Velkumar)

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. 

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

 

 

Announcements


Top Tags