Page 1 of 2
Calling a flow with arguments/parameters
Posted: 07 Mar 2019 08:45
by elektroinside
I think this would fundamentally change the way we build our flows: transforming the flow concept into a function, with multi-threading support.
We can already pass to the calling flow some variables, but what about calling a flow with multiple parameters, which can be used to assign values to variables inside the called flow?
Of course, for this to be complete, the "execute flows" needs to be extended (with UI that adds parameters) and a script function would tremendously help as well.
This way, we can easily repeat complex actions (performed by the called flow itself), building complex "functions", without using multiple global variables, while also allowing parallel executions (because using a single global variable in both calling/executing flow, in the case of multithreading, doesn't work of course).
Re: Calling a flow with arguments/parameters
Posted: 07 Mar 2019 09:51
by anuraag
Its already supported. When action "Execute flows" runs it send all variables of parent flow to child flow.
The executed flow will inherit the execution context with all variables of the parent flow.
The variables usually supplied by the trigger of the target flow will not be available since the trigger of the target flow is bypassed when using this action.
Re: Calling a flow with arguments/parameters
Posted: 07 Mar 2019 10:47
by elektroinside
And how do you stop a particular running instance of a flow, if the flow is called from multiple places? How do you identify the flow's thread so you can act on it, without parameters which you can control, such as an ID, in paralel executions?
So you see, it's not the same thing.
Re: Calling a flow with arguments/parameters
Posted: 07 Mar 2019 10:57
by anuraag
Automagic has Flow execution policy for that
viewtopic.php?f=3&t=6985
Re: Calling a flow with arguments/parameters
Posted: 07 Mar 2019 11:21
by elektroinside
Yes, I know, but it's still not the same thing
You have absolutely 0 control on a particular running instance of a flow, if that flow is called from multiple places (other flows). For example, I want to stop an instance of "Flow X" initially called by "Flow A", but from "Flow B", in the middle of its execution, without running another instance, in the same time not acting on the instance of "Flow X" called by "Flow C".
You can refer (identify) the running instance by assigning/passing it some parameters, like ID (which you can control - because you can't dynamically somehow create a copy of a flow and rename that flow, to execute it). Or pass other parameters, like you do with functions, without automatically copying the entire context of the calling flow, because it's also lighter on the memory.
Re: Calling a flow with arguments/parameters
Posted: 07 Mar 2019 11:42
by anuraag
If i am not wrong you want to say that suppose Flow A and Flow C started instance of Flow X at same time. Now you want to stop Flow X started by Flow A using Flow B.
If thats correct then it's still possible to stop that particular instance using Global Variable and triggername.
Re: Calling a flow with arguments/parameters
Posted: 07 Mar 2019 11:56
by elektroinside
Hmm, i do not know about triggername.
Many thanks, I'll look into it.
Re: Calling a flow with arguments/parameters
Posted: 07 Mar 2019 12:01
by anuraag
elektroinside wrote:Hmm, i do not know about triggername.
Many thanks, I'll look into it.
sorry its called "flow_name".
When a flow is executed there is three variables always present - flow_name, trigger, triggertime
Re: Calling a flow with arguments/parameters
Posted: 07 Mar 2019 12:22
by elektroinside
anuraag wrote:elektroinside wrote:Hmm, i do not know about triggername.
Many thanks, I'll look into it.
sorry its called "flow_name".
When a flow is executed there is three variables always present - flow_name, trigger, triggertime
Hmm, I'm unable to find flow_name in the documentation, only "imported_flow_name".
Re: Calling a flow with arguments/parameters
Posted: 07 Mar 2019 12:42
by anuraag
It's not contain in documentation. You can check it by creating a new flow. Assign trigger or leave it blank. Next attach debug dialog. Run it.
Here flow_name won't help as it changes when child flow is executed. You need to assign a variable before executing another flow or may be variable trigger can be used.