How to make Subflows with dynamic select options in NodeRED

First of, sorry if this question is out of place in this forum.

I am trying to make a Subflow similar to the OpenRPA node “add workitem” but i want to create the option to select a queue from the OpenFlow collection, thus i need the select options in my input to be dynamically set. essentially i am trying to achieve what the “rpa workflow” node does:

image

i have tried to illustrate what i am trying to do with the following subflow:

[
    {
        "id": "31c11eb50a754b96",
        "type": "subflow",
        "name": "subflow_DynDrop",
        "info": "",
        "category": "",
        "in": [
            {
                "x": 340,
                "y": 240,
                "wires": [
                    {
                        "id": "3a49e181a5e727e6"
                    }
                ]
            }
        ],
        "out": [],
        "env": [
            {
                "name": "Input",
                "type": "str",
                "value": "ok",
                "ui": {
                    "type": "select",
                    "opts": {
                        "opts": [
                            {
                                "l": {
                                    "en-US": "option1"
                                },
                                "v": "1"
                            },
                            {
                                "l": {
                                    "en-US": "option2"
                                },
                                "v": "2"
                            },
                            {
                                "l": {
                                    "en-US": "option3"
                                },
                                "v": "3"
                            }
                        ]
                    }
                }
            }
        ],
        "meta": {},
        "color": "#DDAA99",
        "status": {
            "x": 880,
            "y": 160,
            "wires": [
                {
                    "id": "7b5a94334eeebf39",
                    "port": 0
                }
            ]
        }
    },
    {
        "id": "3a49e181a5e727e6",
        "type": "function",
        "z": "31c11eb50a754b96",
        "name": "function 43",
        "func": "msg.payload = env.get(\"Input\")\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "// Code added here will be run once\n// whenever the node is started.\nmsg = {}\n\nmsg.payload = \"XD\"\n\nreturn msg.payload",
        "finalize": "",
        "libs": [],
        "x": 490,
        "y": 240,
        "wires": [
            [
                "d6d10cd652223d34"
            ]
        ]
    },
    {
        "id": "d6d10cd652223d34",
        "type": "debug",
        "z": "31c11eb50a754b96",
        "name": "debug 69",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 660,
        "y": 240,
        "wires": []
    },
    {
        "id": "11afd7873e76afcc",
        "type": "inject",
        "z": "31c11eb50a754b96",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": "1",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 370,
        "y": 160,
        "wires": [
            [
                "4561fe1443d038ea"
            ]
        ]
    },
    {
        "id": "7b5a94334eeebf39",
        "type": "function",
        "z": "31c11eb50a754b96",
        "name": "status msg",
        "func": "msg.payload = {fill: \"green\", shape: \"dot\", text: \"Node Deployed\"};\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 730,
        "y": 160,
        "wires": [
            []
        ]
    },
    {
        "id": "4561fe1443d038ea",
        "type": "function",
        "z": "31c11eb50a754b96",
        "name": "prep options",
        "func": "let options = [\n    { \"label\": \"dyn1\", \"value\": \"1\" },\n    { \"label\": \"dyn2\", \"value\": \"2\" },\n    { \"label\": \"dyn3\", \"value\": \"3\" }\n]\n\nenv.set(\"options\", options);\n\nreturn msg;\n",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 550,
        "y": 160,
        "wires": [
            [
                "7b5a94334eeebf39"
            ]
        ]
    },
    {
        "id": "9d62537479b9a9b6",
        "type": "subflow:31c11eb50a754b96",
        "z": "68cc313728aaa2b0",
        "name": "",
        "env": [
            {
                "name": "Input",
                "value": "3",
                "type": "str"
            }
        ],
        "x": 1810,
        "y": 160,
        "wires": []
    },
    {
        "id": "646e814584f9bb29",
        "type": "inject",
        "z": "68cc313728aaa2b0",
        "name": "",
        "props": [
            {
                "p": "payload.TS",
                "v": "",
                "vt": "date"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 1570,
        "y": 160,
        "wires": [
            [
                "9d62537479b9a9b6"
            ]
        ]
    }
]

Can this functionality simply not be achieved with a subflow?

Will it have to be implemented as a custom node?

I haven’t created a custom node before so this is new territory for me

I just learned a ton of new things, just from looking at your example. Thank you.

hmmm, it feels really “close” as you are almost there. But from what i can see when clicking around in the ui, it seems select only support an hardcodet list of options.

The workflow selector you show a screenshot of, is actually quite complex. nodered does not have an easy to use, autocomplete feature, so this is created using custom endpoints and a bunch of javascript to allow autocompletion. If the amount of options is not that big, adding a dropdown with all the options, is pretty easy in a custom node.

I don’t have any “easy to follow” examples on how to create a node and publish it on npm, inside nodered. I know there ARE guides out there, but last i checked there was not many and they all seemed hard to follow. The best one I’ve seen is the one the nodered team made them self, but it’s not using typescript, so if you can “live without” that, this is a pretty good getting started guide.

I’m glad I managed to add some value on your end as well! :smiley:

I don’t think it’s worth creating a subflow with hardcoded select options, unfortunately. Instead, I wanted to update the options based on a query result from the OpenFlow collection.

I might try exploring the custom node option a bit. However, I’m a bit intimidated by the idea of experimenting with that in our production environment. I might need to set up a separate Node-RED instance for that.

From the sources I’ve researched(old sources, might exist a solution today) so far, it seems that this functionality indeed requires stepping into custom nodes. Node-REDsrc2021, Google_src2017

It’s unfortunate that subflows don’t have the capability to update their own input properties from within. Such functionality would enable a powerful customization tool to integrate with our current setup utilizing OpenFlow/OpenRPA.

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