Converting inject nodes to function block

I want to convert all inject nodes in my flow to the function node so that I do not have to inject each node manually. I have tried to implement it but only "addVariable3" is being executed. What could be the problem?
I have shared the flow and a few snaps for reference.

Code in function block replacing all inject nodes -

var addFolder = {
    payload: { "opcuaCommand": "addFolder" },
    topic: "ns=1;s=PlantSimulation"

var addVariable1 = {
    payload: { "opcuaCommand": "addVariable" },
    topic: "ns=1;s=CreatePart;datatype=Boolean;value= false"

var addVariable2 = {
    payload: { "opcuaCommand": "addVariable" },
    topic: "ns=1;s=EnterStation;datatype=Boolean;value= false"

var addVariable3 = {
    payload: { "opcuaCommand": "addVariable" },
    topic: "ns=1;s=ExitStation;datatype=Boolean;value= false"

return addFolder, addVariable1, addVariable2, addVariable3;

server_flow.json (5.1 KB)

If you want to return multiple messages I think you must specify multiple outputs in the node setup.
Further, you should return them as an array of messages.

Alternatively take a look at node.send(addFolder), node.send(AddVariable1) etc.

@SK_30 Always good to read the docs.

return [[addFolder, addVariable1, addVariable2, addVariable3]];
1 Like

Thanks @E1cid, as you guessed I've never RTFM.
At least I got the "array" word right :upside_down_face:

1 Like

Sorry jbudd, did i hit the wrong reply button ? The post was meant for @SK_30.

I took your rebuke as well deserved by me whoever it was sent to :slight_smile:
It's OK, I'll survive.

There was no rebuke intended, just sensible advise, so no need for the self-flagellation.

Thank You @E1cid.
I'll try to check the docs first.

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