How can I declare a msg.payload variable inside a json node no make a pdf?

I used a node join to create an array of payloads. Now I need to declare different variables inside a button node using the json format to insert these variables into a pdf (node-red-contrib-pdfmake)
How can I do this?

Sorry that doesn't convey any useful information to me. Can you describe in more detail what you want to get out of the button node? Tell us the structure of the data exactly.

In the title you say json node, did you mean button node?

The node "gerar relatorio" is my json inject and "join" is my node where I created the payload array.
"Gerar relatorio" is an dashboar button (node-red-contrib-dashboard)

and I need to get all msg.payloads that I created inside the "join", and use it inside my json inject. I have to declare variables to each payload in json format

I don't think you can get the button to remember data you send it and then pass it on when clicked. Instead of doing that, feed the button output into the Join node, which I presume you have got in key/value pair mode, and you can check the output of the join for the button topic and only pass that on to the nodes to build your pdf.

Like that?

Yes, but with a Switch node after the Join which passes the message only when the button topic is received. The Join node must be in key/value pair mode, with And every subsequent message selected. I don't know whether you are using key/value mode already.

If not then change to that mode, if you can't then you will need to add another Join node after the first one, with the button fed into that, to join the output from the first with the button press.

And which configuration I should do inside switch node?

Edit: and anyway, my "pdfmake" need to receive the button payload in JSON format to convert into pdf.
And all informations that I need to appear inside the PDF must have in JSON format

I told you, so that it only passes messages with the topic set to that you set in the button, not the topic that you need to set in the other path. I presume you do understand how the join node works in that mode? If not then have a play with it so you understand.

If the data is not in the right format then adjust it as necessary after the switch.

It is possible but requires using msg.topic and some shuffling

[{"id":"98c1b87d53a3afbd","type":"inject","z":"da8a6ef0b3c9a5c8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"button","payload":"{\"one\":1}","payloadType":"json","x":140,"y":480,"wires":[["3854bc21929e8bed"]]},{"id":"3854bc21929e8bed","type":"change","z":"da8a6ef0b3c9a5c8","name":"","rules":[{"t":"move","p":"topic","pt":"msg","to":"topic[0]","tot":"msg"},{"t":"move","p":"payload","pt":"msg","to":"topic[1]","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":500,"wires":[["815e6dc3d2e697c2"]]},{"id":"5a567fdc71f90570","type":"inject","z":"da8a6ef0b3c9a5c8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"button","payload":"{\"two\":2}","payloadType":"json","x":140,"y":540,"wires":[["3854bc21929e8bed"]]},{"id":"815e6dc3d2e697c2","type":"ui_button","z":"da8a6ef0b3c9a5c8","name":"","group":"2d4fe667.28f8ba","order":17,"width":0,"height":0,"passthru":false,"label":"button","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"{}","payloadType":"json","topic":"topic","topicType":"msg","x":490,"y":500,"wires":[["28f8aa05230185d5"]]},{"id":"28f8aa05230185d5","type":"change","z":"da8a6ef0b3c9a5c8","name":"","rules":[{"t":"move","p":"topic[1]","pt":"msg","to":"payload","tot":"msg"},{"t":"move","p":"topic[0]","pt":"msg","to":"topic","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":500,"wires":[["b3af9a4094965b6b"]]},{"id":"b3af9a4094965b6b","type":"debug","z":"da8a6ef0b3c9a5c8","name":"debug 115","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":550,"y":560,"wires":[]},{"id":"2d4fe667.28f8ba","type":"ui_group","name":"demo","tab":"1caa8458.b17814","order":2,"disp":true,"width":"12","collapse":false},{"id":"1caa8458.b17814","type":"ui_tab","name":"Demo","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

I like it. A bit of lateral thinking can go a long way.

@Eduardo1 that is a simpler solution than mine.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.