Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X
Hi! i have read alot of documentation but cant find how to do this in TW9.5 i get succes on everything but it just adds empty lines in my infotable. i have added the json and service below
{"station":"station_3","Artikelnr":2053,"antal":46,"vo":767,"Embalage":"Packaging_3","operator":"Operator_4","Antalskort":3}
var dataTableName = "Proddata";
var dataShapeName = ".datashape.lucas";
var result = "Success";
try {
var dataToAdd = dataToAdd;
var jsonData = JSON.parse(dataToAdd);
logger.debug("Incoming JSON data: " + jsonData);
// Directly access the InfoTable property on the Thing
var infoTable = me[dataTableName];
// Directly create a ValueCollection from the JSON data
var rowValues = new Object();
rowValues.station = jsonData.station;
rowValues.Artikelnr = jsonData.Artikelnr;
rowValues.antal = jsonData.antal;
rowValues.vo = jsonData.vo;
rowValues.Embalage = jsonData.Embalage;
rowValues.operator = jsonData.operator;
rowValues.Antalskort = jsonData.Antalskort;
logger.debug("Row values created: " + JSON.stringify(rowValues));
// var stringifyRowValues = JSON.stringify(rowValues);
logger.debug('RowValues to use' + (rowValues) );
// Add the row to the existing InfoTable
infoTable.AddRow({
row: rowValues
});
logger.info("Data added to InfoTable successfully!");
} catch (err) {
logger.error("Error processing data: " + err.message);
result = "Error: " + err.message;
}
result;
Solved! Go to Solution.
Hi @LL_10926685 ,
Kindly find this below code it may helps you. If any queries kindly do let me know.
var dataTableName = "Proddata";
var dataShapeName = ".datashape.lucas";
var result = "Success";
try {
// Assuming dataToAdd is coming from somewhere within the code or an input
var jsonData = JSON.parse(dataToAdd);
logger.debug("Incoming JSON data: " + JSON.stringify(jsonData));
// Directly access the InfoTable property on the Thing
var infoTable = me[dataTableName];
// Create a new row object to match the expected structure of the InfoTable
var rowValues = {
station: jsonData.station,
Artikelnr: jsonData.Artikelnr,
antal: jsonData.antal,
vo: jsonData.vo,
Embalage: jsonData.Embalage,
operator: jsonData.operator,
Antalskort: jsonData.Antalskort
};
logger.debug("Row values created: " + JSON.stringify(rowValues));
// Add the row to the existing InfoTable
infoTable.AddRow(rowValues);
logger.info("Data added to InfoTable successfully!");
} catch (err) {
logger.error("Error processing data: " + err.message);
result = "Error: " + err.message;
}
result;
Thanks & Regards,
Arun C
Hi @LL_10926685 ,
Kindly find this below code it may helps you. If any queries kindly do let me know.
var dataTableName = "Proddata";
var dataShapeName = ".datashape.lucas";
var result = "Success";
try {
// Assuming dataToAdd is coming from somewhere within the code or an input
var jsonData = JSON.parse(dataToAdd);
logger.debug("Incoming JSON data: " + JSON.stringify(jsonData));
// Directly access the InfoTable property on the Thing
var infoTable = me[dataTableName];
// Create a new row object to match the expected structure of the InfoTable
var rowValues = {
station: jsonData.station,
Artikelnr: jsonData.Artikelnr,
antal: jsonData.antal,
vo: jsonData.vo,
Embalage: jsonData.Embalage,
operator: jsonData.operator,
Antalskort: jsonData.Antalskort
};
logger.debug("Row values created: " + JSON.stringify(rowValues));
// Add the row to the existing InfoTable
infoTable.AddRow(rowValues);
logger.info("Data added to InfoTable successfully!");
} catch (err) {
logger.error("Error processing data: " + err.message);
result = "Error: " + err.message;
}
result;
Thanks & Regards,
Arun C