I am trying to build my first workflow. The final purpose is to trigger a clound function using and API but I need to get some data before into a MySQL database. I need for this to execute a SQL query for each value from an array. I want to do this in Python but I cannot trigger my SQL query and send dynamic parameter. Do you have any why ?
Here is a picture of my workflow.
For your workflow, what you are trying to do should be handled as a function call. On the left side of your canvas you should see the function icon where you can setup the MySQL query:
In this space, you can create the SQL query you want to execute in your loop and then call that in your python code. Additionally, there is no need to use the trigger() syntax for this -- functions are called like functionName(param1, param2...)
I have included two ways of calling the loop -- first using the code block you are already using but changing the syntax and second using the Loop block component, which takes an array input and uses the alias value to refer to each iterated item.
Let me know if you want any clarification on the above!
I've made the same flow as yours but I still get errors when I run it. As I show in the first image, I need to loop over each ID nested in the JSON sample currently defined in the startTrigger.
{
"env": "ABC-implem",
"env_type": "IMPLEM",
"rules": [
{
"id": 179,
"rule_name": "MY TEST 1",
"rule_type": "REF_FLIGHT_SQL"
},
{
"id": 22,
"rule_name": "MY TEST 2 ",
"rule_type": "REF_FLIGHT_SQL"
}
]
}
Here is a new screenshoot from what I get. (I also tried with {{value.id}}
As @ferret141 aptly describes, you just need to extract the data from the startTrigger and use that in your loop functions/blocks. All of these methods should work out once you are running through only the data you need to loop.
I can run my worflow when I have some data into the Test Json parameters but the final objective is to send this data from an app. So I trigger the workflow from the app using the native process on retool. When I check the log I have the data in the startTriggers but not in the javascript block behind. I tried with .data or .data.value or .value but nothing works.
Do you have any why ?
It looks like your code block is still just using the default values from the workflow setup. Can you post a screenshot of the code1 block?
What you should do in that block is test a return value, so if you got rid of all the stuff in that block and replaced it with return startTrigger.data you should see the same set of data from your App in both the startTrigger node and the code1 node outputs.
If you trigger from the app, come back to the workflow and check the run history for the last run, what does the node data say (don't forget to deploy the workflow)