In this lesson you’ll learn:
-
How to add a Loop (For Each) step to process multiple items
-
How to download each file from a URL
-
How to upload each file to the correct Google Drive folder
Introduction
In the previous lesson, we created an array of file URLs using the Code Step. Now it’s time to process each file individually by looping through the array.
Using the Loop (For Each) step, we can download each file and upload it directly to a Google Drive folder. This approach works whether the user uploaded one file or hundreds of files—your workflow will automatically handle them all!
Step 1: Create a Google Drive Folder for the Files
Before we start looping through the files, let’s create a dedicated folder in Google Drive to store them. This folder will be dynamically named using the patient’s Name and Date of Birth, ensuring all files stay organized under the correct patient record.
How to Create the Folder:
-
Click the ➕ icon after the Code Step.
-
Select the Google Drive connector and choose the Create Folder action.
-
Configure the Folder Name field using dynamic data from the Jotform trigger:
-
Save and test the step to make the data of the folder available in your workflow and ensure that it works as expected.
Now that the folder is created, we’ll use it in the next step to store all uploaded files.
Step 2: Add a Loop (For Each) Step
-
Click the ➕ icon after the Google Drive / Create folder step.
-
Select For Each (Loop) from the Logic section.
-
Configure the Loop:
-
Input Array: Map this to the
files
output from your Code Step.
-
- Save and Test the step: So each item from the array of files to be available inside the loop for further mapping to actions inside the loop.
💡 Tip: The Loop will run once for each URL in the array. You can access the current item using the
Loop Item
variable in each step inside the loop.
Step 3: Download Each File
-
Inside the Loop, click ➕ Add to loop to add a new step.
-
Select the Jotform connector and the Download File from answer action.
-
Map the File URL to the current
Loop Item
—this contains the URL for the current file being processed. - Save the step.
-
Test the loop action again to download the files in Jotform and make their file URLs available for uploading to Google Drive.
New File URLs
As you can see from the test outputs, the "Download file from answer" step ran twice since there are two files in the form, and their ready-to-upload URLs became available in the workflow data.
Learn more about files
You can check more on working with files inside a workflow in our article here.
Step 3: Upload the File to Google Drive
-
After downloading the file, add another step inside the loop.
-
Select the Google Drive connector and choose the Upload File action.
-
Map the Folder input to be the folder id variable that is available from our previous step "Create folder" action.
- For the File input, map it to the URL variable that is available from the "Download file from answer" action inside our loop.
- Save the step.
Step 4: Test the Loop
-
Select the "For Each" step in our workflow and click the "Test step" button for the loop to run once again and perform their inside actions.
-
Verify that each file is downloaded and uploaded successfully to Google Drive.
-
Check the Google Drive folder to confirm the files appear correctly.
Success!
Our workflow identified the two files the patient uploaded in Jotform, downloaded them, and uploaded them to their respective folder in Google Drive.
You’ve now automated the processing of multiple files, no matter how many the user submits.
Next Lesson
Now that you’ve mastered looping through files, let’s take automation even further by making a custom HTTP API call to DrChrono for an advanced action that’s not yet supported in Keragon.
Next Lesson: Make a Custom HTTP API Call using the HTTP connector