In the previous lecture, he learned about some flows, some fluids provide an easy way to organize
your flows so that you can reuse parts.
And in this lecture, I wanted to take another step and take another look into such flows and show you
three different ways by which you can exchange data between a flow and a flow in this lecture.
I have taken the example from the previous lecture and extended it in order to do my three demonstrations.
I'm going to show you how to exchange data between a flow and its flow.
First, by using flow variables.
What I want to show you how to use global variables.
And finally, how to return one or more values from my flow.
Lack of court in this case a right here.
But let's start from the beginning.
Obviously, the easiest way to exchange data between a flow and other flows as well as between a flow
and a sub flow, is to use our global variable.
So in this example, I've got my trigger, as you see in the previous lecture of editor, a little delay
here because there's a few things that are happening as well that I want to make sure that the timings
are correct.
But after 1/2 we go into the DHT 22 sub flow, which we can see here.
This node will go to the sensor and grab the temperature and humidity and print them into the debug
window, but also use these two change nodes to set a global temperature variable and a global humidity
variable, as you can see here.
So just use the global context from the dropdown here.
Back in our main flow.
We wait for 5 seconds and then I use the change node to grab the values stored in the global temperature
and global humidity variables and then set them into the message payload and message humidity variable
should then those can then be printed into the output.
Just like that.
So let's run it.
I'm going to trigger the flow.
Give it a bit of time, especially for the 5 seconds, so that we can grab the global temperatures.
And here they are.
So humidity global and temperature global.
And they say values.
Those values, again, were set inside the flow, using these to know which is to change routes.
So this is easy again.
You can use the same technique to communicate values across flows in a project.
If you want to be a little bit more precise about who has access or which flow, as you'd say, has
access to a particular value, then global via voice is a bit of an overkill.
It's like using a global variable in a regular program.
Best to be avoided and best to have a little bit more control set in.
So another way you can go about doing this is to use a flow variable.
A parent variable can share its flow variables with a sub flow and I'll show you how.
So here we've got the trigger.
I've set the trigger so that it will store the timestamp into the message payload attribute.
So once I click on this button to trigger the trigger node, I will go into the change node.
And in the change node I take the payload time and date stamp and store it in a flow context variable
called trigger time.
So flow don't trigger time.
Then wait for a second and go into the sub flow and inside the sub flow.
Right here in this function I have a little bit of JavaScript code which uses the flow to get API call.
And what I want to do is to get the value stored in the flow trigger time or flow don't actually get
time.
But because this flow trigger time value is stored in a flow variable that was created by the parent
of these sub flow, I need to prepare a dollar sign parent to the name of the variable that I'm accessing.
So.
So the result is that I'm using float to get and then in parentheses it's dollar sign parent which gives
me access to the flu virus of the parent dot trigger time, which is a name of the variable that I want
to access.
I take the content of this.
Variable in my JavaScript program and store it in the payload of the message and then return that message
once the triggered time that is stored in the parent's flow variable is captured by my JavaScript,
it printed out into the debug window by this debug node and the name of this node is Print Flow Timestamp.
That's the one that I'm going to look for in a moment.
When I trigger the flow switch, go back to the main flow and trigger it.
And.
Here is the print flow timestamp output, which is this number here, which is identical to the timestamp
variable that came out of the trigger mode.
Okay.
So this is the second way by which you can exchange data between a flow and any of its sub flows.
I also wanted to show you a way by which you can return one or more values from a subfloor.
You can see it here.
I've got my DHT 22 subfloor, and you can see that there are two connectors coming out of it that I
then connect to debug notes.
The way you can do this is first in your sub flow to create as many outputs as you need.
So in this case I've got two outputs.
I can add more and you can see that output nodes appear.
Or can delete them and then you need to provide some value going into this output set will be then exposed
to the main flow.
In my case, I used a function in this function of got a little bit of JavaScript.
This JavaScript creates the humidity and temperature variables in the humidity variable.
I store message the payload attribute temperature Walsh store message dot humidity attribute.
And then for my return statement, I've got an array and in an array of call it means JSON statement
where I've got two payloads.
One payload has the value of temperature, the second payload, the value of humidity.
And from there I've got my two output connectors which are connect to the output nodes for my stuff
flew.
These will then come out into the main flow where I can connect them to other nodes.
In this case, two other debug nodes for this trigger.
This flow one more time and see what comes out of these two specific nodes.
It's going to take 1/2 to show supply.
Temperature is right here and then the low flow humidity is right here.
Returned by the flew.
And to recap.
There are a few ways by which you can exchange data between a flow and sub flows, and in this lecture
I showed you three of those ways.
It can use flow variables which are accessible from a sub flow.
By using the parent preprint in the name of the flow variable that you want to access, then you can
use global variables which allow data exchange across any flow or sub flows in a project.
And finally, you've learned how you can return one or more values from a sub flow using the function.