In this lesson you’ll learn:
-
How to use the Code Step to manipulate data
-
How to convert a data string into an array (list) of files
-
How to prepare the array for processing in a loop
Introduction
In our existing workflow, the input we receive from the form contains a single string that holds file information. This might include one file, two files, or even a dynamic number of files, depending on what the user submitted.
We can see this if we "Test the trigger" and see the "File Upload" data variable that conatins teh files:
However, to properly process these files—download them, upload them to a data store location, and perform actions for each - we need to convert this string into an array of files.
This is exactly where the Code Step comes in. With just a few lines of JQ code, we can split the string and generate an array that the workflow can loop through.
What Does the Input Data Look Like?
-
Raw Input (String):
"<a href=\"https://www.jotform.com/uploads/christsogas/250353395672057/6230247055311644125/back-of-card-3.jpg\" target=\"_blank\" title=\"back-of-card-3.jpg\">back-of-card-3.jpg</a><br><a href=\"https://www.jotform.com/uploads/christsogas/250353395672057/6230247055311644125/insurance-front.png\" target=\"_blank\" title=\"insurance-front.png\">insurance-front.png</a>"
-
What We Need (Array):
[
"https://www.jotform.com/uploads/christsogas/250353395672057/6230247055311644125/insurance-front.png",
"https://www.jotform.com/uploads/christsogas/250353395672057/6230247055311644125/back-of-card-3.jpg",
]
Step 1: Add a Code Step
-
Click the ➕ icon after the "Continue if" action.
-
Navigate to Helpers then Data Helpers and then Code Step.
Step 2: Write the Code to Split the String
Before writing the code, let’s map the input data correctly:
-
In the Code Step, define a data variable that we will reference it to our code, for example, name it
files
. -
Map this variable to the File Upload field from the Jotform trigger.
Now, let’s write the code to extract the URLs from the raw HTML string provided by Jotform.
.Files | [ scan("https?://[^\" ]+") ]
Step 3: Test the Code Step
-
Click Test Step to run the code and verify the output.
-
Confirm that the output is a clean array of file URLs.
Success!
After testing our step we can see that the ouput is an array with all the file URLs
Next lesson
Now that we have a clean array of files, we can move on to the next step—looping through the array to process each file individually.
Next Lesson: Loop Through the Files and Upload Them to Google Drive