Using Switches/Branches Variables after their expression
I would like to know how I can use variables from switches or branches after their execution.
You can see in the attached image that I tried it with an OR expression to either use the first switch case or the default switch case, depending on which were executed. This works if it goes through the first case but fails when it goes through the second case, because the OR condition checks the first case first.
The reason why I am not setting up the GPT4-Vision within each switch case is because I have a lot of nodes that come after the switch case and they would all be the same. The only difference would be the GPT4-Vision prompt with the according variables from switch case 1 and the default case.
How can I solve this issue?
Solution:Jump to solution
Hey, I missed updating the remix link, here is the correct version - https://buildship.app/remix/56ca7d42-f1ed-4cca-bd5b-0b13153185ef.
with the updated logic. This should work. @Brian...
BuildShip - Visual backend workflow builder
Visually build workflows and powerful backend logic for your apps. Powered by AI, connect to anything with or without code.
10 Replies
AI Support Bot Information
<@112676328783802368> you can react on the relevant answer (message) with a ✅ in this thread when you think it has been solved, by the bot or by a human!
Anyone can react on this message with a ❌ if the GPT bot is unhelpful or hallucinating answers.
Please note: Team members will review and answer the questions on best efforts basis.
By the way, the docs mention that I can use the Switch Node as a variable. https://docs.buildship.com/core-nodes/switch#return
Is this still up to date, because I cannot do so.
Switch Node – BuildShip
A unified resource to start building your backend with low-code. Dive into triggers, nodes, and step-by-step guidance to jumpstart your workflow creation.
Hi Brian, the docs says that you can use the
returned value
of the executed case, in the above screenshot you shared, the concatenate string node
never executed due to which it's result value will be undefined. You'll be require to use GPT-4 in 1st case as well.I know about the error and return values, but I do not want to add the nodes that follow after the switch into each single case as I mentioned before. Is there no other solution? The resulting error is triggered by the Buildship ctx, so maybe there is a way of not throwing that error and instead consider the OR condition to use the next ctx variable.
the error will be thrown if the variable is undefined, but you can setup an onFail on the node to handle it and use Execute workflow to use the next ctx variable - https://docs.buildship.com/features/node-failure
Handle Node Failure – BuildShip
A unified resource to start building your backend with low-code. Dive into triggers, nodes, and step-by-step guidance to jumpstart your workflow creation.
To be more specific. I get the error: "Cannot read properties of undefined (reading '64a19a5c-2ce6-47ee-8fb6-5b64d63f5f47')" This is the id of the node, isn't it? If the string would actually be "undefined" then I would get a different error.
I cannot use an "on fail" due to many reasons. Firstly this would not work with a switch case with more than 2 cases since we cannot do an onFail catch in a custom on Fail workflow. Secondly it is just more messy. It would be nice if we can just check if the node is undefined or not, so I can use an OR operator in my case. Isn't this somehow possible? Like with " if ctx[switch].[case1] != undefined "?
@Brian, okay, you can use ternary operators to handle this sanitation, refer to the image and this remix link for example and usage.
here's a remix link - https://buildship.app/remix/56ca7d42-f1ed-4cca-bd5b-0b13153185ef. This will ensure to work in both cases even if the case1 node is executed or not. Let me know if helps to move forward
BuildShip - Visual backend workflow builder
Visually build workflows and powerful backend logic for your apps. Powered by AI, connect to anything with or without code.
I just checked it and your method just prints the nodes path, including the operation. You also give this to the GPT4 Vision which makes not much sense, since this is not the output text. Or am I missing something?
Solution
Hey, I missed updating the remix link, here is the correct version - https://buildship.app/remix/56ca7d42-f1ed-4cca-bd5b-0b13153185ef.
with the updated logic. This should work. @Brian
BuildShip - Visual backend workflow builder
Visually build workflows and powerful backend logic for your apps. Powered by AI, connect to anything with or without code.