Hi all,
actually, storing an object into the flow drives me crazy.
If I process the code below, I got always the String "[object Object]" stored in the flow and even if I return it to the debug it is the same string returned.
I assume I pass somewhere the object to a string but where?
/* Definition of classConsumptions */
function classConsumptions() {
this.valuePairs = [];
function classPair(key, value) {
this.key = key;
this. value = value;
}
this.addValue = function(key, value) {
/* Check if key exists */
var indexKey = this.valuePairs.findIndex(i => i.key === key)
switch (indexKey) {
case -1:
this.valuePairs.push(new classPair(key, value));
break;
default:
this.valuePairs[indexKey].value = value;
break;
}
}
this.printComsumptionsToDebug = function(){
this.valuePairs.forEach(function(element) {
node.warn("Key: " + element.key + " Value: " + element.value);
})
}
}
/* Main */
var localConsumptions = flow.get("consumptions");
localConsumptions = ( typeof localConsumptions != "undefined" && localConsumptions instanceof Object ) ? localConsumptions : new classConsumptions();
localConsumptions.addValue(msg.topic, msg.payload);
flow.set("consumptions", localConsumptions);
return localConsumptions;
Thanks for your help.