Accessing Flow Information From Custom Node

Hi,

I am trying to get the Flow Info within my custom node on input event as follows:

this.on('input', function (msg, nodeSend, nodeDone) {
            console.info(node.name + " processing start");
            node.start_time = Date.now();
            console.debug("Capturing active flow details - begin");
            const activeWorkspaceId = RED.workspaces.active();
            node.activeflow = RED.nodes.workspace(activeWorkspaceId);
            if (!node.activeflow) {
                // this is probably a subflow
                node.activeSubflow = RED.nodes.subflow(activeWorkspaceId);
                console.debug(node.activeSubflow.info);
            } else {
                console.debug(node.activeflow.info);
            }
});

However I am getting error as follows:

%s - %s 30 Jun 12:07:12 [error] TypeError: Cannot read property 'active' of undefined

Kindly help with this issue.

Regards

RED.workspaces.active is part of the editor, i.e. you run on the client-side.

this.on('input') however takes place on the server-side. Luckily your custom node keeps track of where it belongs. node._flow should contain everything you're looking for.

1 Like

What problem are you actually trying to solve here?

Nodes shouldn't care where the input comes from or behave differently depending where they are.

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