Is there a way to pass variables to a “Sub workflow”?
There is no way to pass in variables but you can pass in flow-data.
The input data of the “Execute Workflow Node” is at the same time the output of the Start-Node in the called workflow. The output data of the last node of the executed workflow will be the same as the output of the “Execute Workflow” Node.
so that would be $node[“Start”].data[“”]?
Yes exactly. The expression on a parameter would be something like:
{{$node["Start"].data["propertyName"]}}
Hm, strange. So both nodes are in the sub-workflow and they are connected?
I just tested. It works great for me.
Main workflow (do not forget to change the worklow ID):
Sub-Workflow:
ok, i see it works, but i’m calling it after a ‘\’ because this is a file path. maybe i need to escape it somehow?
Yes, it seems like the backslash is causing problems. It works in the UI but somehow when it gets executed it messes things up:
So for now I guess you have to “create” the value in a Function-Node in then reference it in the node you need it like in this example:
Nice. i will do that. thanks!
should i raise a but for it?
n8n is using under the hood the great riot-tmpl
module for expressions. So it is actually going “wrong” in there. Just opened in issue there, asking if it is really a bug or if I can fix it with some configuration:
https://github.com/riot/tmpl/issues/23
Hi,
First off thanks for this great project. So far I have been copying JSON to re-use workflows. Executing a child workflow with variables sounds a lot better.
At the moment, did I understand well that the “caller” needs to know/find out all references to $node[‘start’].data manually? I think the proposal or adding explicit variables is interesting.
They could be added as visible properties to the Start node, and read by Execute Workflow to prompt for values. Triggering a flow with variables directly could either fail, or prompt for values for debugging.
This is how NodeRed handles subflows, and I think explicit variables makes it very easy to discover the feature, and robust as the caller is given a clear interface (without having to look under the hood).
Of course it could be optional and the start flow could still inherit all of the caller’s output.
Hello @romain! Welcome to the community.
Yes, you understand that correctly. For now, I would simply copy example input data and then paste it in a Function-Node after the Start-Node. Best to add a NoOp-Node after the Function one to be able to reference data from that node (to have one fixed start-point). You can then always when you want to test, simply activate/deactivate the Function-Node.
Thanks a lot for the input. It is very helpful! It is planned to add something similar to what you described to make the process easier in the future. As like you realized it is currently not optimal. Sadly have however no estimate yet as the workaround (even though it is not great) is not too complicated and I want to make sure that the functionality we implement here can also be used for another realted feature that is planned.
Thanks for the idea, the “sample” function node is a good starting workaround for now. I will keep an eye on announcements in the future! Thanks
Just wanted to share that the approach worked well, thank you.
I can just think of two nice-to-have things that would help with legibility:
- being able to set the required variables from within “Execute Workflow” itself
- displaying the workflow name instead of the ID underneath
To illustrate, this is the corresponding NodeRed equivalent where the purpose of the child workflow is obvious:
Sorry about the comparison, I understand the products are quite different but subflows is one of the things it does quite well.
Great to hear that it works well!
Yes agree displaying the Workflow-Name instead of the ID would be much nicer. That is however technically not possible. Or sure it would be possible but would require quite some work which it would simply not be worth right now.
Thanks a lot, will check how Node-Red handles that.
Hi,
I have a total of 2 HTTP requests. One for the Login and the other for getting user data after login.
The First HTTP request is successful and returns a token.
In the Second HTTP request I am saving the token in the headers like
Headers: {
authorization : Bearer {{$node[“HTTP Request”].data[“token”]}}
}
which is showing my token when I give the expression like
Headers : {
authorization: Bearer eyJhbGciOiJIUzI1NiIsI…
}
But when I execute the work flow it is not executing and showing something like “Workflow Execution Crashed”
When I execute only the second node it is giving me response.
Is there any thing wrong which I am doing or any changes which I have to do?
Hey @BhanuPrakash!
Welcome to the community
Can you please create a different topic? Also can you share how you’re running n8n and the workflow that you are trying to execute? You can refer to the documentation if you’re not sure how to share a workflow
Thanks for the quick reply I will create a new topic.