# Display global context in the edit dialog of a custom node

**URL:** <https://discourse.nodered.org/t/display-global-context-in-the-edit-dialog-of-a-custom-node/68378>\
**Category:** Developing Nodes\
**Created:** [29 September 2022 09:46 UTC](https://discourse.nodered.org/t/display-global-context-in-the-edit-dialog-of-a-custom-node/68378 "2022-09-29T09:46:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![SkyMound](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@SkyMound](https://discourse.nodered.org/u/SkyMound)\
**Post date:** [29 September 2022 09:46 UTC](https://discourse.nodered.org/t/display-global-context-in-the-edit-dialog-of-a-custom-node/68378/1 "2022-09-29T09:46:16Z")

</div>

Hello, i'm stuck on something.

When editing a node in the edit dialog, i want the "user" to be able to select an item from a list stored in the global context.

I already create an http endpoint, then when we open the edit dialog tab, it requests the runtime for values.

_html file_

```auto
oneditprepare : function(){
            $.getJSON('listStored',function(data) {
                $("#node-input-list").typedInput({
                    types: [
                        {
                            value: "list",
                            options: [
                                { value: "", label: "--Select an item--"},
                                ...data
                            ]
                        }
                    ]
                })
            });
        }

```

_js file_

```auto
RED.httpAdmin.get("/listStored", RED.auth.needsPermission('node.read'), function(req,res) {
        let listFromGlobal = //How to access global context from here

        res.json(listFromGlobal);
});

```

But from here how to access the global context ?  
I looked at the documentation on RED module butunderstand how to use it

---

<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:** [29 September 2022 09:59 UTC](https://discourse.nodered.org/t/display-global-context-in-the-edit-dialog-of-a-custom-node/68378/2 "2022-09-29T09:59:50Z")

</div>

In general you shouldn't be exposing global context in this way.

How does that list get into global context to begin with?

The runtime already provides an endpoint for querying context - as used by the context sidebar. I don't have the specific details to hand, but if you use the browser tools to examine the network requests the editor makes when you have the context sidebar open and click the 'refresh' button, you should be able to identify the endpoint.

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [29 September 2022 12:43 UTC](https://discourse.nodered.org/t/display-global-context-in-the-edit-dialog-of-a-custom-node/68378/3 "2022-09-29T12:43:08Z")

</div>

Following @knolleary advice I got: [http://127.0.0.1:1880/context/global](http://127.0.0.1:1880/context/global)

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [29 September 2022 12:51 UTC](https://discourse.nodered.org/t/display-global-context-in-the-edit-dialog-of-a-custom-node/68378/4 "2022-09-29T12:51:10Z")

</div>

You can also get specifics:

```auto
http://red.localhost:1880/red/context/node/a440f5977ec34da8/uib_cache?store=default

```

Notes:

- My admin root is set to `/red/` - use a relative URL to avoid having to worry about locations.
- That gets a node's context variable with a specific name and a given store.

You can also update context this way:

```auto
http://red.localhost:1880/red/inject/a4f2bd730664b927

```

Notes:

- Use POST rather than GET

* * *

Doh! It hadn't occurred to me to try that method when I put together uibuilder's caching node. I did it via an API call. Though in my case, not sure that this method helps that much since I need the same functions in the js file of the node anyway - all it saves is an API endpoint and they use pretty much all standard code.

---

<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:** [29 September 2022 13:13 UTC](https://discourse.nodered.org/t/display-global-context-in-the-edit-dialog-of-a-custom-node/68378/5 "2022-09-29T13:13:11Z")

</div>

> [@TotallyInformation](#):
>
> You can also update context this way:

There is no api for updating context from the editor. The url you shared there is the one to trigger an inject node - that has nothing to do with context.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [29 September 2022 13:14 UTC](https://discourse.nodered.org/t/display-global-context-in-the-edit-dialog-of-a-custom-node/68378/6 "2022-09-29T13:14:44Z")

</div>

Ah. OK. That makes sense.

---

<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:** [28 November 2022 13:15 UTC](https://discourse.nodered.org/t/display-global-context-in-the-edit-dialog-of-a-custom-node/68378/7 "2022-11-28T13:15:22Z")

</div>

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