Node Creation oneditprepare

This should also be stored automatically for you. Perhaps you are setting this manually?

There are helper functions to do this: RED.util.evaluateNodeProperty

e.g...

function myNode(config) {
    RED.nodes.createNode(this, config)
    const node = this
    node.inField = config.inField || "payload"
    node.inFieldType = config.inFieldType || "msg"

    node.on('input', function (msg) {
        let inField
        RED.util.evaluateNodeProperty(node.inField, node.inFieldType, node, msg, (err, value) => {
            if (err) {
                node.error("Unable to evaluate inField", msg)
                node.status({ fill: "red", shape: "ring", text: "Unable to evaluate inField" })
                return//halt flow!
            } else {
                inField = value
            }
        })
        // do stuff with inField
    })
}
RED.nodes.registerType("myNode", myNode)

https://nodered.org/docs/api/ui/typedInput/#examples

1 Like