Change filename for write Node dynamical and string change handling

So far, so good—I managed to do it in one day, but I'm a complete novice and come from LabView, where I can do something like this in 10 minutes... but anyway. Here's an example: my question is, is there any way to do this without a function node, especially when handling strings for the file name?
function:
msg.filename = '/home/rr/Dokumente/Logger/testloggera_' + flow.get("NowDate") + '.txt';
return msg;

[
    {
        "id": "3ad48c473fea5513",
        "type": "function",
        "z": "80ea8d142ccb0bd4",
        "name": "setze filename mit NowDate neu zusammen",
        "func": "  msg.filename = '/home/rr/Dokumente/Logger/testloggera_' + flow.get(\"NowDate\") + '.txt';\n    return msg;\n",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 850,
        "y": 500,
        "wires": [
            [
                "b37f712221ebfe5f",
                "1dfaff9af10ddb0e",
                "806a9b21564b40f0"
            ]
        ]
    }


]

You could use Jsonata in a change node

[{"id":"0d1266049d9698cf","type":"change","z":"d14258870cbe9738","name":"","rules":[{"t":"set","p":"filename","pt":"msg","to":"'/home/rr/Dokumente/Logger/testloggera_' & $flowContext(\"NowDate\") & '.txt'","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":225,"wires":[["6526a6d0ad6fbad0"]]}]
1 Like

Yes i now :sweat_smile: but is it without any scripting possible?

You could use mustache syntax in a template node but NowDate would have to be a message property rather than a flow context variable. (Why are you using a flow context variable anyway?)

One of the big mysteries for me is the use of templates and what a mustach is—what a funny name. I've only shown an excerpt of my project here. The variable flow.NowDate is used elsewhere as a decision maker...
But thanks again, I'm coming from LabView where everything works without scripting! But LV has its quirks too... me hoppe is/was also NR is script free, :wink:

The name mustache clearly derives from it's use in this (admittedly uncommon) smiley :-{)

A really big mystery is how the ! came to be called Bang!

I've never heard of LabView. How would you concatenate the strings in that?

This is not a very Node-red approach, though of course it is possible to code it like this.
A flow context variable can be changed at any time by the arrival of a new message.
The Node-red approach would be to generate the value and attach it as a message property. Then the value is passed along the flow* and is unaffected by a new input

* Most nodes follow the rule of passing on such message properties unaffected. Some contrib nodes fail to do this.

You can do this in the change node without scripting, but why not use JSONata direct in file write node?

example of change node with no scripting

[{"id":"0d1266049d9698cf","type":"change","z":"613df62afc8a16bf","name":"","rules":[{"t":"set","p":"filename","pt":"msg","to":"/home/rr/Dokumente/Logger/testloggera_*#*.txt","tot":"str"},{"t":"set","p":"NowDate","pt":"msg","to":"NowDate","tot":"flow"},{"t":"change","p":"filename","pt":"msg","from":"*#*","fromt":"str","to":"NowDate","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":80,"wires":[["e99af74c636b45c0"]]}]

thx @E1cid cool string solution: but, the idea is to use the flow variable for the next incoming message in comparison, since the flow variable is kept constant... which currently works, but strangely enough, I can't display the variable in the contxt view, which is odd? With the debug Node and Jeson : $flowContext("neudate") get undefind (Rasberry/Linux)? But in Test Mode on Linux PC it works...
@jbudd Labview you can real works only with Icons without any Scripting the complex project wath i have ever seen was an Helicopter-Test landing without a Pilot :wink: ...

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