Is there a way to read select option of a custom node edit form from an external file?

I'm writing a custom node which allow to edit properties from a limited set of choices.
So I would like to read that properties from an external file (for example a csv).

Is there a way to do that?

Thanks in advance.

Hi @gbove73

to do something like that you need your node's editor code to make a custom HTTP request back to the runtime where you can have some code that handles that request by reading the file and returning whatever it needs to.

This StackOverflow answer gives a general description of how to do that, using the Serial node as an example - https://stackoverflow.com/questions/41567175/send-data-on-configuration/41567832#41567832

Thanks a lot.

This is my solution.

First af all, I've built a flow to serve http on endpoint /configuration1 reading a csv from filesystem.

Then, on .html i put:

 <div class="form-row">
    <label for="node-input-myAttribute"><i class="icon-tag"></i> My Attribute</label>
    <select id="node-input-myAttribute">
        <option value=""></option>
    </select>
</div>

and:

oneditprepare: function () {
        var def = this.myAttribute;
        $.ajax({
            url: 'http://127.0.0.1:1880/configuration1',
            success: function(contents) {
                var lines = contents.split("\n");
                var options = [];
                lines.forEach((line) => {
                    var field = line.split(";");
                    options.push(field);
                });
                options.forEach(function (o) {
                    var x = document.getElementById("node-input-myAttribute");
                    var option = document.createElement("option");
                    option.text = o[1] + " (" + o[0] + ")";
                    option.value = o[0];
                    if (o[0] === def) {
                        option.selected = true;
                    }
                    x.add(option);
                });
            }
        });

Why have you done that as a flow and not as code in your node's .js file? I would not recommend you building logic needed to configure your node as part of your flow.

because I want to be able to decide the source of the csv data without modifying the code (file name, path, etc.).

You could make that a configuration option in the node.