2. Create an Array of Files Using a Code Step

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:

files.png

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",
]

 

🤖 The fastest way is to describe it in the chat panel (left side of the editor): "Add a Code Step after the Continue If step." Click Update workflow to confirm.

Manual option

Step 1: Add a Code Step

  1. Click the ➕ icon after the "Continue if" action.

  2. 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:

  1. In the Code Step, define a data variable that we will reference it to our code, for example, name it files.

  2. Map this variable to the File Upload field from the Jotform trigger.
    codestep-1.gif

Now, let’s write the code to extract the URLs from the raw HTML string provided by Jotform.

If you need help writing or adjusting the code, describe what you need in the chat: "Help me write JQ code to extract all URLs from this HTML string."

.Files | [ scan("https?://[^\" ]+") ]

Need Help with Code Steps?

If you’re new to writing code in workflows or want to learn more about using the Code Step effectively, check out our detailed guide:

Using Code Steps in Workflows

Step 3: Test the Code Step

  1. Click Test Step to run the code and verify the output.

  2. 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

Was this article helpful?
0 out of 1 found this helpful

Articles in this section