TypeError: Cannot convert undefined or null to object
That isn't what I said.
To unserstand what is going on, we need all relavint info at the same time.
change your function to this ↓ and show is what you get in the debug panel
if (typeof msg.payload !== 'object') {
node.error('expected msg.payload to be an object')
return
}
const resultArray = Object.values(msg.payload.result)
if (Array.isArray(resultArray ) && resultArray.length >= 2) {
msg.payload = resultArray[1]
return msg;
} else {
node.error('Object.values(msg.payload.result) is not an array or does not have 2 or more elements')
}
OK folks, I'll try it now in german:
[{"id":"d686e0ddf37b8661","type":"inject","z":"5a1cda5786c898fd","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":220,"y":120,"wires":[["99e86353658eee4b"]]},{"id":"99e86353658eee4b","type":"function","z":"5a1cda5786c898fd","name":"function 2","func":"var test = {\n payload:\n {\n result:\n {\n \"2023-08-27\": 9996787,\n \"2023-08-28\": 11724368\n }\n }\n};\n\nreturn test;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":120,"wires":[["df3c8905088381de","6ebdec126ab41e03"]]},{"id":"df3c8905088381de","type":"debug","z":"5a1cda5786c898fd","name":"debug 40","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":680,"y":80,"wires":[]},{"id":"6ebdec126ab41e03","type":"function","z":"5a1cda5786c898fd","name":"function 3","func":"msg.payload = Object.values(msg.payload.result)[1];\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":680,"y":140,"wires":[["0998ab2bc1c304a0"]]},{"id":"0998ab2bc1c304a0","type":"debug","z":"5a1cda5786c898fd","name":"debug 41","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":860,"y":140,"wires":[]}]
Das ist ein ganz einfacher Flow mit einem Inject, 2 Funktions-Nodes und 2 Debugs.
[Edit] Der erste Funktions-Node simuliert Deine Daten, der zweite extrahiert das gewünschte Ergebnis.
Der erste Debug zeigt genau Deine Struktur, der zweite genau das gewünschte Ergebnis.
Du musst an irgendeiner anderen Stelle etwas falsch machen!?
As you can see it works. The issue you might have is unexpected payloads hitting the function. The code I offered you will check everything is as you expect & will let you know if it is not!
Ok the output of the solar forcast node on the second output is
[{"labels":["",""],"data":[],"series":[]}]
You want the output of the first output
{"result":{"2023-08-27":16313510,"2023-08-28":10678228},"message":{"code":0,"type":"success","text":"","pid":"164i6btQ","info":{"latitude":51.0769,"longitude":6.2243,"distance":0,"place":"Erkelenzer Straße 16C, 41836 Hückelhoven, Germany","timezone":"Europe/Berlin","time":"2023-08-27T16:51:16+02:00","time_utc":"2023-08-27T14:51:16+00:00"},"ratelimit":{"period":3600,"limit":12,"remaining":11}}}
So the function works but you are feeding it the wrong output
sorry colin, i have test it. The same error .... after that i make the changes back .... and then i get the screenshot
sorry the same error!
I doubt that. Show us the debug output
OMG ! SORRY
I have copy the same node above with other functions
OMG ! SORRY Thank you everyone !
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.