How can I dynamically generate parameters in a function node instead of passing them directly in the inject node?

I have a flow in Node-RED where I want to send a command to hide a column in a table. Here's what I have so far:

[
    {
        "id": "1621c5074273825e",
        "type": "inject",
        "z": "74c40cd627e77aca",
        "name": "",
        "props": [
            {
                "p": "tbCmd",
                "v": "hideColumn",
                "vt": "str"
            },
            {
                "p": "tbArgs",
                "v": "[\"age\"]",
                "vt": "jsonata"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 190,
        "y": 220,
        "wires": [
            [
                "ca04f55efd2044b0"
            ]
        ]
    }
]

Currently, I’m passing tbCmd and tbArgs parameters directly from the inject node. However, I would like to know if it's possible to handle the generation of tbCmd and tbArgs dynamically through a function node without passing them explicitly in the inject node.

How can I implement this behavior

[
   {
        "id": "3e8fef9d569346b1",
        "type": "function",
        "z": "74c40cd627e77aca",
        "name": "Generate Command",
        "func": "msg.tbCmd = 'hideColumn';\nmsg.tbArgs = ['age'];\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 390,
        "y": 220,
        "wires": [
            [
                "ca04f55efd2044b0"
            ]
        ]
    }
]

how can i achieve hide functionality using the function node by triggering the inject node ,without giving the property in the inject node
[moderator edit, to form a correctly formated flow json]

If you just want a message with the two properties and no other properties.

msg = {
    tbCmd: 'hideColumn',
    tbArgs: ['age']
}
return msg;

thanks this is what i exactly did in my tabulator. but individually it is working. but my aim if user is admin it will hide column if other than admin means i want to hide another column.

[
    {
        "id": "74c40cd627e77aca",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "ca04f55efd2044b0",
        "type": "ui-tabulator",
        "z": "74c40cd627e77aca",
        "name": "",
        "group": "9951c110473fa414",
        "initObj": "{\n   \"height\": 400,\n   \"layout\": \"fitColumns\",\n   \"columns\": [\n      {\"field\": \"id\", \"visible\": false},\n      {\"title\": \"Name\", \"field\": \"name\" ,\"hozAlign\": \"left\"},\n      {\"title\": \"Age\", \"field\": \"age\", \"hozAlign\": \"center\",\"visible\": true},\n      {\"title\": \"Gender\", \"field\": \"gender\", \"hozAlign\": \"center\"},\n      {\"title\": \"Occupation\", \"field\": \"occupation\", \"hozAlign\": \"left\"},\n      {\"title\": \"City\", \"field\": \"city\",\"hozAlign\": \"left\"}\n   ],\n   \"data\": [\n      {\"id\": 1, \"name\": \"John Brown\", \"age\": 30, \"gender\": \"Male\", \"occupation\": \"Engineer\", \"city\": \"New York\"},\n      {\"id\": 2, \"name\": \"Betty Clark\", \"age\": 25, \"gender\": \"Female\", \"occupation\": \"Designer\", \"city\": \"Los Angeles\"},\n      {\"id\": 3, \"name\": \"Michael White\", \"age\": 40, \"gender\": \"Male\", \"occupation\": \"Teacher\", \"city\": \"Chicago\"},\n      {\"id\": 4, \"name\": \"Susan Green\", \"age\": 32, \"gender\": \"Female\", \"occupation\": \"Nurse\", \"city\": \"Houston\"},\n      {\"id\": 5, \"name\": \"Tom Black\", \"age\": 28, \"gender\": \"Male\", \"occupation\": \"Lawyer\", \"city\": \"Phoenix\"},\n      {\"id\": 6, \"name\": \"Linda Grey\", \"age\": 35, \"gender\": \"Female\", \"occupation\": \"Chef\", \"city\": \"Philadelphia\"},\n      {\"id\": 7, \"name\": \"Kevin Brown\", \"age\": 29, \"gender\": \"Male\", \"occupation\": \"Developer\", \"city\": \"San Antonio\"},\n      {\"id\": 8, \"name\": \"Emma White\", \"age\": 26, \"gender\": \"Female\", \"occupation\": \"Data Analyst\", \"city\": \"San Diego\"},\n      {\"id\": 9, \"name\": \"James Blue\", \"age\": 42, \"gender\": \"Male\", \"occupation\": \"Architect\", \"city\": \"Dallas\"},\n      {\"id\": 10, \"name\": \"Mary Yellow\", \"age\": 37, \"gender\": \"Female\", \"occupation\": \"Doctor\", \"city\": \"San Jose\"}\n   ]\n}\n",
        "maxWidth": "70em",
        "events": "",
        "order": 1,
        "multiUser": false,
        "validateRowIds": false,
        "themeCSS": "",
        "themeFile": "",
        "tblDivId": "",
        "printToLog": false,
        "width": 0,
        "height": 0,
        "x": 690,
        "y": 280,
        "wires": [
            [
                "f01c7a86855919e8"
            ]
        ]
    },
    {
        "id": "1621c5074273825e",
        "type": "inject",
        "z": "74c40cd627e77aca",
        "name": "",
        "props": [
            {
                "p": "tbCmd",
                "v": "hideColumn",
                "vt": "str"
            },
            {
                "p": "tbArgs",
                "v": "[\"age\"]",
                "vt": "jsonata"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 90,
        "y": 260,
        "wires": [
            [
                "0f5341a99ec4ba46"
            ]
        ]
    },
    {
        "id": "f01c7a86855919e8",
        "type": "debug",
        "z": "74c40cd627e77aca",
        "name": "debug 2581",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 730,
        "y": 220,
        "wires": []
    },
    {
        "id": "c90d3a61be398bde",
        "type": "function",
        "z": "74c40cd627e77aca",
        "name": "function 94",
        "func": "msg = {\n    tbCmd: 'hideColumn',\n    tbArgs: ['age']\n}\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 390,
        "y": 220,
        "wires": [
            [
                "ca04f55efd2044b0"
            ]
        ]
    },
    {
        "id": "8604c80709f3e7f5",
        "type": "function",
        "z": "74c40cd627e77aca",
        "name": "function 95",
        "func": "msg = {\n    tbCmd: 'hideColumn',\n    tbArgs: ['city']\n}\nreturn msg;\n",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 390,
        "y": 320,
        "wires": [
            [
                "ca04f55efd2044b0"
            ]
        ]
    },
    {
        "id": "0f5341a99ec4ba46",
        "type": "switch",
        "z": "74c40cd627e77aca",
        "name": "",
        "property": "_client.user.user",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "admin",
                "vt": "str"
            },
            {
                "t": "neq",
                "v": "admin",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 232,
        "y": 263,
        "wires": [
            [
                "c90d3a61be398bde"
            ],
            [
                "8604c80709f3e7f5"
            ]
        ]
    },
    {
        "id": "9951c110473fa414",
        "type": "ui-group",
        "name": "tablehide",
        "page": "c0382248f2f34bf7",
        "width": "12",
        "height": "1",
        "order": 1,
        "showTitle": true,
        "className": "",
        "visible": "true",
        "disabled": "false",
        "groupType": "default"
    },
    {
        "id": "c0382248f2f34bf7",
        "type": "ui-page",
        "name": "table hide",
        "ui": "64fc71361e24a0d0",
        "path": "/page3",
        "icon": "home",
        "layout": "grid",
        "theme": "default",
        "breakpoints": [
            {
                "name": "Default",
                "px": "0",
                "cols": "3"
            },
            {
                "name": "Tablet",
                "px": "576",
                "cols": "6"
            },
            {
                "name": "Small Desktop",
                "px": "768",
                "cols": "9"
            },
            {
                "name": "Desktop",
                "px": "1024",
                "cols": "12"
            }
        ],
        "order": 3,
        "className": "",
        "visible": true,
        "disabled": false
    },
    {
        "id": "64fc71361e24a0d0",
        "type": "ui-base",
        "name": "",
        "path": "/dashboard",
        "appIcon": "",
        "includeClientData": true,
        "acceptsClientConfig": [
            "ui-iframe",
            "ui-control",
            "ui-template",
            "ui-gauge",
            "ui-chart",
            "ui-slider",
            "ui-form",
            "ui-text-input",
            "ui-number-input",
            "ui-file-input",
            "ui-button",
            "ui-button-group",
            "ui-dropdown",
            "ui-radio-group",
            "ui-switch",
            "ui-text",
            "ui-chart",
            "ui-form",
            "ui-number-input",
            "ui-switch",
            "ui-table",
            "ui-gauge",
            "ui-markdown",
            "ui-iframe",
            "ui-tabulator",
            "ui-radio-group",
            "ui-dropdown",
            "ui-button-group",
            "ui-file-input"
        ],
        "showPathInSidebar": false,
        "showPageTitle": false,
        "navigationStyle": "icon",
        "titleBarStyle": "fixed"
    }
]

this is my flow.if i login with admin it will .hide age column others means it will hide city column. give me some guidance

Your explanation is not clear so I am assuming you want to reshow the hiden columns. I have not use ui-dashboard2-tabulator yet, my best guess is something like this

[{"id":"1621c5074273825e","type":"inject","z":"74c40cd627e77aca","name":"","props":[{"p":"tbCmd","v":"hideColumn","vt":"str"},{"p":"tbArgs","v":"[\"age\"]","vt":"jsonata"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":90,"y":260,"wires":[["0f5341a99ec4ba46"]]},{"id":"0f5341a99ec4ba46","type":"switch","z":"74c40cd627e77aca","name":"","property":"_client.user.user","propertyType":"msg","rules":[{"t":"eq","v":"admin","vt":"str"},{"t":"neq","v":"admin","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":232,"y":263,"wires":[["c90d3a61be398bde"],["8604c80709f3e7f5"]]},{"id":"c90d3a61be398bde","type":"function","z":"74c40cd627e77aca","name":"function 94","func":"msg = [\n    {\n        tbCmd: 'hideColumn',\n        tbArgs: ['age']\n    },\n    {\n        tbCmd: 'showColumn',\n        tbArgs: ['city']   \n    }\n]\nreturn [msg];","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":390,"y":220,"wires":[["f01c7a86855919e8"]]},{"id":"8604c80709f3e7f5","type":"function","z":"74c40cd627e77aca","name":"function 95","func":"msg = [\n    {\n        tbCmd: 'hideColumn',\n        tbArgs: ['city']\n    },\n    {\n        tbCmd: 'showColumn',\n        tbArgs: ['age']\n    }\n]\nreturn [msg];","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":390,"y":320,"wires":[["f01c7a86855919e8"]]},{"id":"f01c7a86855919e8","type":"debug","z":"74c40cd627e77aca","name":"debug 2581","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":730,"y":220,"wires":[]}]

I’m working on a Node-RED flow where I want to conditionally hide columns based on the user’s role right after they log in. Specifically:

  • If the user is an admin, I want to hide the "age" column.
  • If the user is not an admin, I want to hide the "city" column.

Is that not what your example flow does. Please explain what your example is not doing correctly.

what i am trying means,i have two use user one is admin another is guest. if i login with the user,then the table column of age only should hide,if i login with guest then it will hide city column. based on the user authentication i want to hide the columns.

for example code below what i achieved means, here i m using the same concept if my user is admin it will hide one pages of design pattern examples and my user is guest means it will hide the page1 page

[
    {
        "id": "75ee70ce74d754fb",
        "type": "group",
        "z": "cb37e8a97b7683a2",
        "style": {
            "stroke": "#999999",
            "stroke-opacity": "1",
            "fill": "none",
            "fill-opacity": "1",
            "label": true,
            "label-position": "nw",
            "color": "#a4a4a4"
        },
        "nodes": [
            "908f16ab945682ce",
            "945a9cd4baff9e73",
            "eb2ae34b9c293797",
            "c17ff1c761e2e211",
            "b4498914429e3e7f",
            "4092102a679b5bc7",
            "a03eb50a95db9d5b",
            "a207052fe9103830",
            "d79965f2d8072879",
            "88b356c07f4a75a5"
        ],
        "x": 34,
        "y": 359,
        "w": 812,
        "h": 222
    },
    {
        "id": "908f16ab945682ce",
        "type": "ui-event",
        "z": "cb37e8a97b7683a2",
        "g": "75ee70ce74d754fb",
        "ui": "64fc71361e24a0d0",
        "name": "",
        "x": 110,
        "y": 480,
        "wires": [
            [
                "eb2ae34b9c293797"
            ]
        ]
    },
    {
        "id": "945a9cd4baff9e73",
        "type": "comment",
        "z": "cb37e8a97b7683a2",
        "g": "75ee70ce74d754fb",
        "name": "Client-Defined Data",
        "info": "",
        "x": 270,
        "y": 400,
        "wires": []
    },
    {
        "id": "eb2ae34b9c293797",
        "type": "switch",
        "z": "cb37e8a97b7683a2",
        "g": "75ee70ce74d754fb",
        "name": "",
        "property": "_client.user.user",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "admin",
                "vt": "str"
            },
            {
                "t": "neq",
                "v": "admin",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 250,
        "y": 480,
        "wires": [
            [
                "a03eb50a95db9d5b"
            ],
            [
                "b4498914429e3e7f",
                "a207052fe9103830"
            ]
        ]
    },
    {
        "id": "c17ff1c761e2e211",
        "type": "ui-template",
        "z": "cb37e8a97b7683a2",
        "g": "75ee70ce74d754fb",
        "group": "",
        "page": "",
        "ui": "",
        "name": "",
        "order": 1,
        "width": 0,
        "height": 0,
        "head": "",
        "format": "<template>\n    <strong>msg._client:</strong>\n    <pre>{{ msg._client.user.user }}</pre>\n</template>",
        "storeOutMessages": true,
        "passthru": true,
        "resendOnRefresh": true,
        "templateScope": "local",
        "className": "",
        "x": 760,
        "y": 440,
        "wires": [
            []
        ]
    },
    {
        "id": "b4498914429e3e7f",
        "type": "debug",
        "z": "cb37e8a97b7683a2",
        "g": "75ee70ce74d754fb",
        "name": "debug 25",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 740,
        "y": 480,
        "wires": []
    },
    {
        "id": "4092102a679b5bc7",
        "type": "ui-control",
        "z": "cb37e8a97b7683a2",
        "g": "75ee70ce74d754fb",
        "name": "",
        "ui": "64fc71361e24a0d0",
        "events": "all",
        "x": 600,
        "y": 440,
        "wires": [
            [
                "c17ff1c761e2e211"
            ]
        ]
    },
    {
        "id": "a03eb50a95db9d5b",
        "type": "function",
        "z": "cb37e8a97b7683a2",
        "g": "75ee70ce74d754fb",
        "name": "function 8",
        "func": "msg.payload = {\n       pages: {\n        hide: ['Design Pattern Examples']\n    }\n    // groups: {\n    //     hide: ['gauge:slidegauge']\n    // }\n}\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 440,
        "y": 440,
        "wires": [
            [
                "4092102a679b5bc7"
            ]
        ]
    },
    {
        "id": "a207052fe9103830",
        "type": "function",
        "z": "cb37e8a97b7683a2",
        "g": "75ee70ce74d754fb",
        "name": "function 9",
        "func": "msg.payload = {\n       pages: {\n        hide: ['Page 1']\n    }\n    // groups: {\n    //     hide: ['gauge:chart']\n    // }\n}\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 440,
        "y": 540,
        "wires": [
            [
                "d79965f2d8072879"
            ]
        ]
    },
    {
        "id": "d79965f2d8072879",
        "type": "ui-control",
        "z": "cb37e8a97b7683a2",
        "g": "75ee70ce74d754fb",
        "name": "",
        "ui": "64fc71361e24a0d0",
        "events": "all",
        "x": 600,
        "y": 540,
        "wires": [
            [
                "88b356c07f4a75a5"
            ]
        ]
    },
    {
        "id": "88b356c07f4a75a5",
        "type": "ui-template",
        "z": "cb37e8a97b7683a2",
        "g": "75ee70ce74d754fb",
        "group": "",
        "page": "",
        "ui": "",
        "name": "",
        "order": 2,
        "width": 0,
        "height": 0,
        "head": "",
        "format": "<template>\n    <strong>msg._client:</strong>\n    <pre>{{ msg._client.user.user }}</pre>\n</template>",
        "storeOutMessages": true,
        "passthru": true,
        "resendOnRefresh": true,
        "templateScope": "local",
        "className": "",
        "x": 760,
        "y": 540,
        "wires": [
            []
        ]
    },
    {
        "id": "64fc71361e24a0d0",
        "type": "ui-base",
        "name": "",
        "path": "/dashboard",
        "appIcon": "",
        "includeClientData": true,
        "acceptsClientConfig": [
            "ui-iframe",
            "ui-control",
            "ui-template",
            "ui-gauge",
            "ui-chart",
            "ui-slider",
            "ui-form",
            "ui-text-input",
            "ui-number-input",
            "ui-file-input",
            "ui-button",
            "ui-button-group",
            "ui-dropdown",
            "ui-radio-group",
            "ui-switch",
            "ui-text",
            "ui-chart",
            "ui-form",
            "ui-number-input",
            "ui-switch",
            "ui-table",
            "ui-gauge",
            "ui-markdown",
            "ui-iframe",
            "ui-tabulator",
            "ui-radio-group",
            "ui-dropdown",
            "ui-button-group",
            "ui-file-input"
        ],
        "showPathInSidebar": false,
        "showPageTitle": false,
        "navigationStyle": "icon",
        "titleBarStyle": "fixed"
    }
]

the same thing i m trying to implement in the tabulator. hiding the columns based on the users

I understand what you are trying to do. I do not understand what is not working in your example flow.

while i m using different user, the table is not hiding properly . it will show all the columns

But it hides if you use inject nodes?
Please show complete message going into switch node, for both users.
[edit] and messages coming out of switch node.

Not sure I understand what is not working for you, but depending on the user you should hide one column and show the other. Within a function node it can look like:

if (msg.user === "admin")
{
	node.send({
		tbCmd:"hideColumn",
		tbArgs:["age"]
	});
	node.send({
		tbCmd:"showColumn",
		tbArgs:["city"]
	});
}
else
{
	node.send({
		tbCmd:"hideColumn",
		tbArgs:["city"]
	});
	node.send({
		tbCmd:"showColumn",
		tbArgs:["age"]
	});
}