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

**URL:** <https://discourse.nodered.org/t/is-there-a-way-to-read-select-option-of-a-custom-node-edit-form-from-an-external-file/6917>\
**Category:** General\
**Created:** [17 January 2019 13:14 UTC](https://discourse.nodered.org/t/is-there-a-way-to-read-select-option-of-a-custom-node-edit-form-from-an-external-file/6917 "2019-01-17T13:14:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gbove73](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gbove73/32/5078_2.png) [@gbove73](https://discourse.nodered.org/u/gbove73)\
**Post date:** [17 January 2019 13:14 UTC](https://discourse.nodered.org/t/is-there-a-way-to-read-select-option-of-a-custom-node-edit-form-from-an-external-file/6917/1 "2019-01-17T13:14:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [17 January 2019 13:44 UTC](https://discourse.nodered.org/t/is-there-a-way-to-read-select-option-of-a-custom-node-edit-form-from-an-external-file/6917/2 "2019-01-17T13:44:28Z")

</div>

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](https://stackoverflow.com/questions/41567175/send-data-on-configuration/41567832#41567832)

---

<div class="post-metadata">

**Author:** ![gbove73](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gbove73/32/5078_2.png) [@gbove73](https://discourse.nodered.org/u/gbove73)\
**Post date:** [22 January 2019 10:15 UTC](https://discourse.nodered.org/t/is-there-a-way-to-read-select-option-of-a-custom-node-edit-form-from-an-external-file/6917/3 "2019-01-22T10:15:39Z")

</div>

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.

 ![Snip20190122_2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/e/e556035fe0bd96fd607fcb582ccf240c7ff55963.png)

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);
                });
            }
        });
```

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [22 January 2019 10:25 UTC](https://discourse.nodered.org/t/is-there-a-way-to-read-select-option-of-a-custom-node-edit-form-from-an-external-file/6917/4 "2019-01-22T10:25:28Z")

</div>

> [@gbove73](#):
>
> First af all, I've built a flow to serve http on endpoint /configuration1 reading a csv from filesystem.

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.

---

<div class="post-metadata">

**Author:** ![gbove73](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gbove73/32/5078_2.png) [@gbove73](https://discourse.nodered.org/u/gbove73)\
**Post date:** [22 January 2019 10:31 UTC](https://discourse.nodered.org/t/is-there-a-way-to-read-select-option-of-a-custom-node-edit-form-from-an-external-file/6917/5 "2019-01-22T10:31:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [22 January 2019 10:33 UTC](https://discourse.nodered.org/t/is-there-a-way-to-read-select-option-of-a-custom-node-edit-form-from-an-external-file/6917/6 "2019-01-22T10:33:12Z")

</div>

> [@gbove73](#):
>
> because I want to be able to decide the source of the csv data without modifying the code

You could make that a configuration option in the node.
