# Context variable scope Group?

**URL:** <https://discourse.nodered.org/t/context-variable-scope-group/78180>\
**Category:** Feature Requests\
**Created:** [4 May 2023 10:38 UTC](https://discourse.nodered.org/t/context-variable-scope-group/78180 "2023-05-04T10:38:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [4 May 2023 10:38 UTC](https://discourse.nodered.org/t/context-variable-scope-group/78180/1 "2023-05-04T10:38:32Z")

</div>

A flow I am constructing for a dashboard has multiple copies of the same nodes.  
 ![Untitled 4](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/f/8f282d5f982701a7b7baea551cae67a555bea990.jpeg)  
(I mistyped "2")  
It would be useful if I could define a context variable **group.arrayidx** so that the source of the data in each field could be the same **msg.payload.contacts[goup.get("arrayidx")]** instead of hard coding the index number **msg.payload.contacts[2]**

In this simple example I could use a change node to set msg.payload.contact = msg.payload.contacts[2] but more complicated dashboards have data derived from more than just one message.

Perhaps there is already an easy way to achieve this?

---

<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:** [4 May 2023 11:06 UTC](https://discourse.nodered.org/t/context-variable-scope-group/78180/2 "2023-05-04T11:06:40Z")

</div>

You could use a group env variable rather than a context var.

```auto
[{"id":"b7afaa489acfae78","type":"group","z":"d5835c53bc24f9f0","name":"","style":{"label":true},"nodes":["a88c4085ec5560c2","d42d2431bb6c0950"],"env":[{"name":"test","value":"aaa","type":"str"}],"x":274,"y":899,"w":452,"h":82},{"id":"a88c4085ec5560c2","type":"inject","z":"d5835c53bc24f9f0","g":"b7afaa489acfae78","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"${test}","payload":"test","payloadType":"env","x":410,"y":940,"wires":[["d42d2431bb6c0950"]]},{"id":"d42d2431bb6c0950","type":"debug","z":"d5835c53bc24f9f0","g":"b7afaa489acfae78","name":"debug 117","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":610,"y":940,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [4 May 2023 11:09 UTC](https://discourse.nodered.org/t/context-variable-scope-group/78180/3 "2023-05-04T11:09:41Z")

</div>

In a change node before the ui nodes you can do:-  
set `msg.``a_property_name`  
to `flow.` `arrayidx`  
Then in same change node you can do  
set `msg.``whatever_property`  
to `msg.`  
`payload.contacts[msg.a_property_name]`

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [7 May 2023 09:50 UTC](https://discourse.nodered.org/t/context-variable-scope-group/78180/4 "2023-05-07T09:50:47Z")

</div>

Thanks.

I resolved this issue by routeing all the group input & output into a single function and used context.  
If only the UI group could be dynamically set by a message property all would be great.

I must get round to looking at environment variables.

---

<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:** [6 July 2023 09:50 UTC](https://discourse.nodered.org/t/context-variable-scope-group/78180/5 "2023-07-06T09:50:49Z")

</div>

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