# JSONata in subflow interface

**URL:** <https://discourse.nodered.org/t/jsonata-in-subflow-interface/59813>\
**Category:** Feature Requests\
**Created:** [13 March 2022 19:40 UTC](https://discourse.nodered.org/t/jsonata-in-subflow-interface/59813 "2022-03-13T19:40:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![msillano](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/msillano/32/17424_2.png) [@msillano](https://discourse.nodered.org/u/msillano)\
**Post date:** [13 March 2022 19:40 UTC](https://discourse.nodered.org/t/jsonata-in-subflow-interface/59813/1 "2022-03-13T19:40:52Z")

</div>

The lack of any form of ~~dynamic option~~ indirect definition (?) in subflow input interface is, for me, sometime a big limit.

Subflow interface:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/5/35c66b6b711e7b14b1626906a21d9e135d7fc326.png)

More useful (from inject node):  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/7/7775f4f4c2a9ba20d1c769ef1f1d07bd2a4a352d.png)

My personal 'workaround':

Rule: if a string starts with '@' then it is replaced by the result of eval(substring(1))  
Code inside the subflow:

```auto
     var xvalue = env.get("value").toString().trim();
     if (xvalue.startsWith('@')){
          xvalue = eval(xvalue.substring(1));
          } else 
         xvalue = env.get("value");
 

```

Of course it is not perfect, but it works ~~with strings~~.  
Any better solution waiting an upgrade of the 'subflow' properties interface?

Best regards  
m.s.

---

<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 March 2022 20:31 UTC](https://discourse.nodered.org/t/jsonata-in-subflow-interface/59813/2 "2022-03-13T20:31:31Z")

</div>

Not 100% sure what you are doing here?

Do you have an example of what you send in `value`? Then what does it `eval`uate to?

Lastly, why not simply pass values in `msg.xxx`?

---

<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:** [13 March 2022 22:00 UTC](https://discourse.nodered.org/t/jsonata-in-subflow-interface/59813/3 "2022-03-13T22:00:54Z")

</div>

The subflow properties are statically evaluated when the flow is started. They cannot be dynamic.

If you want to pass in dynamic values, using the msg you pass in.

---

<div class="post-metadata">

**Author:** ![msillano](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/msillano/32/17424_2.png) [@msillano](https://discourse.nodered.org/u/msillano)\
**Post date:** [14 March 2022 06:53 UTC](https://discourse.nodered.org/t/jsonata-in-subflow-interface/59813/4 "2022-03-14T06:53:13Z")

</div>

@Steve-Mcl, Use case:  
in a\_\_flow:  
`global.set("user_defied_config", "foo");` (e.g. using node-red-contib-config, works in 'On Start').

in b\_flow:  
`my_subflow( "@global.get('user_defined_config')" )` ( replaced by 'foo' )  
desirable alternatives:  
`my_subflow( [global.]user_defined_config)`  
`my_subflow([J:]$globalContext("user_defined_config")) `

in c\_flow:  
`my_subflow( "bar" )`

@knolleary thanks, clear argument, but for me it is not a case of dynamic evaluation, but of (quasi-static) indirect definition.  
Or not? i.e. the unique solution is my workaround? (it allows a dynamic evaluation).

Why not insert some new code into the subflow interface, to also accept [global.] [flow.] [J:expression] [timestamp] ?

Similar limitations are present in many "contrib" nodes, where the programmer too often just uses [text] .

In conclusion, the limits imposed on the subflow, if they are a deliberate choice, are unreasonable and harmful.

---

<div class="post-metadata">

**Author:** ![msillano](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/msillano/32/17424_2.png) [@msillano](https://discourse.nodered.org/u/msillano)\
**Post date:** [18 March 2022 16:47 UTC](https://discourse.nodered.org/t/jsonata-in-subflow-interface/59813/5 "2022-03-18T16:47:03Z")

</div>

see an implementation [here](https://discourse.nodered.org/t/subflows-and-configuration-late-and-runtime-parameters-binding/60042)

Geetings.  
m.s.

---

<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:** [17 May 2022 16:47 UTC](https://discourse.nodered.org/t/jsonata-in-subflow-interface/59813/6 "2022-05-17T16:47:57Z")

</div>

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