I am currently working with workflows. I have an array in a resource (getScans), I want to loop through this array, and want to insert data in the table that I have connected with, but with a loop.
How can I do that?
I have results in processedScans. I am looping through the array, and in the next resource, I want to add the data in database one by one.
Hello AmmarHere's how you can go about it:
Loop through your "getScans" array using a loop component in Retool.
For each iteration, you'll have a "current item" from the array. You can use that item and send it as a parameter to the next resource, which is responsible for adding data to your database.
In the next resource, you should be able to use that parameter to insert data into your database.
So, essentially, you're breaking down the process into steps, and with each iteration of the loop, you send the current item as a parameter to your database update resource.
Just make sure your database resource is set up to accept parameters, and you should be good to go! If you need more specific help, feel free to share more details with the community for a more detailed response. Good luck
Thank you for the response. Can you please share how I can call the next resource that is responsible for adding the data to the database?
For example: Lets just say I am in the loop, I have a currentValue, and want to send it to the next resource, and that resource should be able to retrieve that currentValue (ongoing loop).
The rest of the information I can understand it. Thank you!
to call the next resource that adds data to the database, you can follow these steps:
in your loop: you have the "current item" from the loop, right? you're already halfway there. when you have that current value, you're almost ready to send it to the next resource
set up the next resource: in Retool, you'll have a separate resource for adding data to the database; make sure this resource can accept parameters.
pass the value: Inside your loop, after you've got the "current item," you'll use an action or function (depends on how you've set it up) to call that next resource
pass the value as a parameter: when you call the next resource, you'll typically have an option to send it a parameter. this is where you send the "current item" you got from the loop
database resource uses the parameter: in ur next resource (the one that adds data to the database), make sure it's set up to use the parameter you just sent. it should be able to take that "current item" as a parameter and use it in the database operation
So, basically, you're passing the //current item// as a parameter from your loop to the next resource, and the next resource should be configured to accept and use this parameter in its database operation. This way, it keeps working in an ongoing loop
Thank you for your response.
Can you please share with me how to configure the second resource to accept the parameter? I have been trying to set it up like that but unable to do so.
Hi @Ammar_Flatline_Agency! Our docs on functions might be helpful here You can click through the image example and set up a sample function. Let me know if you still have questions about setting up your own functions