# How does the UI access global “config” data

**URL:** <https://discourse.nodered.org/t/how-does-the-ui-access-global-config-data/66737>\
**Category:** Developing Nodes\
**Created:** [22 August 2022 04:36 UTC](https://discourse.nodered.org/t/how-does-the-ui-access-global-config-data/66737 "2022-08-22T04:36:29Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![mbenson](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mbenson/32/66625_2.png) [@mbenson](https://discourse.nodered.org/u/mbenson)\
**Post date:** [22 August 2022 04:36 UTC](https://discourse.nodered.org/t/how-does-the-ui-access-global-config-data/66737/1 "2022-08-22T04:36:29Z")

</div>

I’m writing a plugin that has a global “config” component that contains IP, port, username, and password for a remote server. The user then sets an ID in the node which corresponds to data supplied by the server. The server can contain thousands of individual data items, so I wrote the plugin so the the user can basically query the server for the correct ID. For now, I’m hard coding the server IP, port, username, and password for proof of concept. How can I get that information from the global “config”?

I’m still learning Node Red. If I understand correctly, the global “config” is code that runs on the node server side, and the Ui code runs on the browser side, I am very familiar with Node application development so I know how exchange data between client and server, if I have to do it myself. But I assume there are Node Red specific methods.

---

<div class="post-metadata">

**Author:** ![tve](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tve/32/59475_2.png) [@tve](https://discourse.nodered.org/u/tve)\
**Post date:** [22 August 2022 05:09 UTC](https://discourse.nodered.org/t/how-does-the-ui-access-global-config-data/66737/2 "2022-08-22T05:09:00Z")

</div>

> [@mbenson](#):
>
> I’m writing a plugin

Are you writing a plugin or a node? Nothing in your description suggests to me that you should be writing a plugin, but I may not understand...

> [@mbenson](#):
>
> I wrote the plugin so the the user can basically query the server for the correct ID

Where is that code located? In a .js file running on Node.js or in a .html file running in the browser?

Maybe you can explain what your node(s) are intended to do in a bit more detail? Or point to some code? Or paste some fragments of code here?

---

<div class="post-metadata">

**Author:** ![mbenson](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mbenson/32/66625_2.png) [@mbenson](https://discourse.nodered.org/u/mbenson)\
**Post date:** [22 August 2022 05:51 UTC](https://discourse.nodered.org/t/how-does-the-ui-access-global-config-data/66737/3 "2022-08-22T05:51:58Z")

</div>

My code is at:

> **[GitHub - WindhoverLabs/node-red-contrib-yamcs: Node Red plugin supporting...](https://github.com/WindhoverLabs/node-red-contrib-yamcs)**
>
> Node Red plugin supporting YAMCS integration. Contribute to WindhoverLabs/node-red-contrib-yamcs development by creating an account on GitHub.

YAMCS is a open source ground control system typically used to remotely control and monitor spacecraft. It has a web.based API. I am writing code (plugin, node, whatever it should be called) that interfaces to YAMCS via the web based API. I actually got it working without having to write any code, using a few of the existing nodes together. I’m writing code to make a specialized node specifically for YAMCS.

The code I wrote let’s you specify the server first, and associate the node with the server configuration. Tabbed completed, you’ll enter the name of the parameter. When you deploy, it will login to the server, subscribe to the parameter[s), and send a message containing the current t value of the parameter enter every time there is a new update. I have all that working. I’m just making it more convenient for the user by combining multiple nodes into a single node.

For an added convenience, as you enter in the qualified path and name of the parameter enter, it queries the server and shows you suggestions. Similar to when you enter in Google queries. That part currently executes entirely on the browser side, though I might move some of that to the node side to proxy the connection so I can’t avoid CORS issues. I have this feature working too, but I have the ip, port, and other configuration hard coded. I want to read it from the config.

---

<div class="post-metadata">

**Author:** ![hardillb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hardillb/32/12373_2.png) [@hardillb](https://discourse.nodered.org/u/hardillb)\
**Post date:** [22 August 2022 21:00 UTC](https://discourse.nodered.org/t/how-does-the-ui-access-global-config-data/66737/4 "2022-08-22T21:00:17Z")

</div>

The context isn't really meant for holding configuration information (to start with the default context isn't persistent)

Config should be stored in the flow, with transient state in the context.

---

<div class="post-metadata">

**Author:** ![mbenson](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mbenson/32/66625_2.png) [@mbenson](https://discourse.nodered.org/u/mbenson)\
**Post date:** [22 August 2022 21:33 UTC](https://discourse.nodered.org/t/how-does-the-ui-access-global-config-data/66737/5 "2022-08-22T21:33:15Z")

</div>

I feel like we're getting wrapped up in terminology. I'm not using the correct terminology here, and I apologize. I'm still learning this project's terminology. Not global data. Its similar to the "Server" property of the "mqtt" node. There is a button with a pencil on it that opens another dialog to either add or edit the "mqtt-broker" node, and where you specify the IP address and the port. Whatever that is called, I have an identical "yamcsconfig" node where you set the server IP and the port. I'm asking how I can read that server IP and port from the UI controller code that runs on the browser side.

---

<div class="post-metadata">

**Author:** ![hardillb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hardillb/32/12373_2.png) [@hardillb](https://discourse.nodered.org/u/hardillb)\
**Post date:** [22 August 2022 22:07 UTC](https://discourse.nodered.org/t/how-does-the-ui-access-global-config-data/66737/6 "2022-08-22T22:07:40Z")

</div>

What you are describing (in the MQTT case) is a config node.

[https://nodered.org/docs/creating-nodes/config-nodes](https://nodered.org/docs/creating-nodes/config-nodes)

Plugins are very different (and currently lacking good documentation). As tve mentioned I suspect you should be [creating Nodes](https://nodered.org/docs/creating-nodes/), not a Plugin.

---

<div class="post-metadata">

**Author:** ![mbenson](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mbenson/32/66625_2.png) [@mbenson](https://discourse.nodered.org/u/mbenson)\
**Post date:** [22 August 2022 22:20 UTC](https://discourse.nodered.org/t/how-does-the-ui-access-global-config-data/66737/7 "2022-08-22T22:20:02Z")

</div>

That might be another miscommunication on my part. I'm not sure what the difference between a plugin and a node is in this case. Judging by the link you just gave me, I am writing a node. None of what I already described is hypothetical. What I wrote, whether its a node or a plugin, is fully functional now. When I run Node Red, I see the "YAMCS" node I created. I can click and drag it to my flow. I can create a new config node and set the IP and port. I can fill in the additional properties and it persists. I'm just trying to determine how I can read the IP and port number from the configuration node.

Once deployed, the code uses this to fulfill its primary purpose by subscribing to data and sending out to the next node(s). But while the user is still configuring the flow, I thought it would be nice to let them query the server for the parameter ID. That part works perfectly. I just have to, temporarily, hard code the IP and port of the server that its querying. As the user enters in the parameter name/id, after X number of characters (currently hard coded to 5), it then starts querying the server for parameters that start with the name already entered. It presents the potential parameters as a drop down. The user can either continue manually entering the parameter in, further refining the search, or click on one of the entries in the drop down list. Basically, I implemented a user select-able autocomplete feature for that particular field.

---

<div class="post-metadata">

**Author:** ![tve](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tve/32/59475_2.png) [@tve](https://discourse.nodered.org/u/tve)\
**Post date:** [23 August 2022 03:37 UTC](https://discourse.nodered.org/t/how-does-the-ui-access-global-config-data/66737/8 "2022-08-23T03:37:34Z")

</div>

Lemme make sure I understand:

- you have a `yamcsconfig` config node that has the server info (IP address, port, creds, etc)
- you have a `yamcs` node
- the yamcs node has a field that is the server field where the user selects the appropriate `yamcsconfig` config node
- the yamcs node has another field where you'd like to populate a drop-down by querying the server
- this means that when the user selects a server, you need to kick off an ajax request to get the info for the drop down
- when the edit dialog is initially brought up you also need to kick off that request
- you're asking "how do I get a handle onto the selected `yamcsconfig` config node so I can construct the request?"

I suspect:

- you need an onchange handler to detect when the user selects a server
- you need the initial ajax request to be sent from the oneditprepare callback
- you can get the selected `yamcsconfig` node ID from the input field that has the `selected` attribute (yeah...)
- you can then get a handle onto the `yamcsconfig` node object by calling `RED.nodes.node(id)`

I'm also pretty sure:

- you will spend quite some time in your browser's "inspect" panel looking for how the server selection drop-down is coded in HTML and how you can tease out the currently selected input
- you will need some stiff drink next to you...
- don't ask me how I know... 😂

---

<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:** [23 August 2022 07:10 UTC](https://discourse.nodered.org/t/how-does-the-ui-access-global-config-data/66737/9 "2022-08-23T07:10:20Z")

</div>

> [@tve](#):
>
> I'm also pretty sure:
> 
> - you will spend quite some time in your browser's "inspect" panel looking for how the server selection drop-down is coded in HTML and how you can tease out the currently selected input
> - you will need some stiff drink next to you...
> - don't ask me how I know... 😂

Or you could just ask. Unless I'm missing something then `$("#id-of-select").val()` would do just that.

---

<div class="post-metadata">

**Author:** ![mbenson](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mbenson/32/66625_2.png) [@mbenson](https://discourse.nodered.org/u/mbenson)\
**Post date:** [23 August 2022 08:12 UTC](https://discourse.nodered.org/t/how-does-the-ui-access-global-config-data/66737/10 "2022-08-23T08:12:02Z")

</div>

Correct. I don’t use ajax, but you get it.

“you can then get a handle onto the yamcsconfig node object by calling RED.nodes.node(id)”

Perfect. That’s exactly what I’m looking for. Thanks!

“you will spend quite some time in your browser's "inspect" panel looking for how the server selection drop-down is coded in HTML and how you can tease out the currently selected input”

I already have it working, but I will still take that drink.

---

<div class="post-metadata">

**Author:** ![mbenson](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mbenson/32/66625_2.png) [@mbenson](https://discourse.nodered.org/u/mbenson)\
**Post date:** [24 August 2022 05:39 UTC](https://discourse.nodered.org/t/how-does-the-ui-access-global-config-data/66737/11 "2022-08-24T05:39:01Z")

</div>

Works great. Thanks again. I should have it polished and in version 1 by Friday.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [23 October 2022 05:39 UTC](https://discourse.nodered.org/t/how-does-the-ui-access-global-config-data/66737/12 "2022-10-23T05:39:39Z")

</div>

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