# Question: Creating a subflow for dynamic accessing a message (one of a given set)

**URL:** <https://discourse.nodered.org/t/question-creating-a-subflow-for-dynamic-accessing-a-message-one-of-a-given-set/48359>\
**Category:** Developing Nodes\
**Created:** [13 July 2021 13:32 UTC](https://discourse.nodered.org/t/question-creating-a-subflow-for-dynamic-accessing-a-message-one-of-a-given-set/48359 "2021-07-13T13:32:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lostbits](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lostbits/32/43407_2.png) [@lostbits](https://discourse.nodered.org/u/lostbits)\
**Post date:** [13 July 2021 13:32 UTC](https://discourse.nodered.org/t/question-creating-a-subflow-for-dynamic-accessing-a-message-one-of-a-given-set/48359/1 "2021-07-13T13:32:37Z")

</div>

Hey,

I am using a subflow to count messages. Since I want to do it more generic, I currently addet an InputPattern via environment..

I do the following:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/d/4de78265b76917873dd7e83854442939a72fede9.png)  
which is working like this:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/8/c8134de1fcf7a8749f1871da6277a8c37fb0b8af.png)

The SubFlow detects node Object msg.payload.Hugo and marks it.

Now I would like to be more flexible and seek for more hand just one level of Object.

So something like finding this:

Input: "msg.payload.Hugo;msg.topic.Hugo"

Currently I only know how to adress the property of a known object. Is there a generic way to do this or pass a msg path like other nodes to a subnode?

Here is the flow:

```auto
[{"id":"3e971524.dac1aa","type":"subflow","name":"Subflow 2","info":"","category":"","in":[{"x":60,"y":40,"wires":[{"id":"d02b4371.12ff3"}]}],"out":[{"x":320,"y":40,"wires":[{"id":"d02b4371.12ff3","port":0}]}],"env":[{"name":"InputPattern","type":"str","value":"Hugo;Ernst;Martin"}],"meta":{},"color":"#DDAA99"},{"id":"d02b4371.12ff3","type":"function","z":"3e971524.dac1aa","name":"","func":"var a=flow.get(\"$parent.demo\")||\"\";\nflow.set(\"$parent.demo\",a);\nvar InputPattern=env.get(\"InputPattern\")||\"unbekannt\";\nvar sSplit=InputPattern.split(\";\");\nmsg.touch=\"true\";\n//just short output first 10 (if present)\nfor (iIndex=0; iIndex<sSplit.length; iIndex++)\n{\n node.warn(iIndex + \":\"+ sSplit[iIndex]);\n if (msg.payload.hasOwnProperty(sSplit[iIndex]))\n {\n node.warn(\"found item\");\n msg.payload[sSplit[iIndex]].found=true;\n }\n else\n {\n node.warn(\"NOT found item\");\n }\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":200,"y":40,"wires":[[]]},{"id":"d7137cc.d7f9e8","type":"subflow:3e971524.dac1aa","z":"b68bfc11.f4d7d","name":"","env":[],"x":340,"y":100,"wires":[["d4cc8977.761cb8"]]},{"id":"6218fdb4.62be24","type":"inject","z":"b68bfc11.f4d7d","name":"Hugo","props":[{"p":"payload.Hugo.Value","v":"OK","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":150,"y":80,"wires":[["d7137cc.d7f9e8"]]},{"id":"d4cc8977.761cb8","type":"debug","z":"b68bfc11.f4d7d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":530,"y":100,"wires":[]},{"id":"368c76c.766918a","type":"inject","z":"b68bfc11.f4d7d","name":"Tim","props":[{"p":"payload.Tim.Value","v":"OK","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":150,"y":120,"wires":[["d7137cc.d7f9e8"]]}]

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [13 July 2021 13:49 UTC](https://discourse.nodered.org/t/question-creating-a-subflow-for-dynamic-accessing-a-message-one-of-a-given-set/48359/2 "2021-07-13T13:49:39Z")

</div>

> [@lostbits](#):
>
> Currently I only know how to adress the property of a known object. Is there a generic way to do this or pass a msg path like other nodes to a subnode?

I think what you are looking for is [bracket notation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors) where you can access an object property by a variable name.

Also, if you want to iterate an objects properties, you will need `Object.keys()` or `Object.entries()` all of which are documented (and the pages often have a dynamic playground) on the [mdn pages](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys)

---

<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:** [11 September 2021 13:50 UTC](https://discourse.nodered.org/t/question-creating-a-subflow-for-dynamic-accessing-a-message-one-of-a-given-set/48359/3 "2021-09-11T13:50:35Z")

</div>

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