Start a loop
Use loop actions A tool for building the processes, logic, and direction within workflows. Actions are the steps the workflow performs to complete a process. to repeatedly run a set of child actions. The Start a loop action runs its child actions while a condition is true. When the condition is no longer true, the workflow proceeds to the next action after the Loop for each container.
The Start a loop action runs child actions while a condition is true. For example, you can use this action to continually reformat a redirect URL until the status code returned by the web service call no longer indicates a redirect.
Before you begin:
-
Understand Variables
-
Understand container actions. You can add actions to create branches such as Branch by stage or to contain other actions such as Action Set that can be collapsed down into a single action high-level view.
Jump to:
Configure the Start a loop action
In the Designer page:
-
Click the Logic and flow action group in the action toolbox.
or
Find actions by browsing action groups, or by typing an action name or function in the Search field at the top of the action toolbox.
-
Drag the Start a loop action to where you want to run a set of actions while a condition is true.
-
Click the Start a loop action.
-
Complete the condition fields:
Note: The maximum number of iterations in a loop is 1000.
-
For When, select the variable you want to evaluate.
-
For Operator, select an operator for comparing the variable to the value.
- For Value, specify a value for the comparison. You can insert a variable or type the value.
-
- Click Add condition to save the new condition.
- For each additional condition you want to add:
- Click Add condition.
Fill in the condition fields:
For When, select the variable you want to evaluate.
For Operator, select an operator for comparing the variable to the value.
- For Value, specify a value for the comparison. You can insert a variable or type the value.
- Click Add condition to save the new condition.
- Select any or all to determine how to evaluate the set of conditions.
For more information on the fields, see Start a loop fields, buttons, and settings.
Field or button | Description | Variable types |
---|---|---|
When | The first value for the condition, such as "Name." Must be a variable. |
Text, Decimal. Integer, Boolean, DateTime |
Operator | The operator for the condition, such as equals (=). Select an operator from the drop-down list. | (n/a) |
Value | The expected value for the When field. | (varies depending on the When selection) |
Add condition | Saves the condition currently being edited. If no edits are taking place, displays fields for defining a new condition. | (n/a) |
all/any | Separates conditions by "AND" (for all) or "OR" (for any). (Displayed when a condition is saved.) | (n/a) |
Displays condition fields for editing. | (n/a) | |
Deletes the indicated condition. | (n/a) |
Example: Continually reformat URL while 300 or 301 status code is returned
In this scenario, your workflow is triggered by a new file in the selected folder on Box.com. The workflow attempts to download the new file through a link. Because Box download links are redirect URLs, the workflow will extract the redirect portion of the URL and retry the URL until download is successful. The workflow then reads the content of the file and performs whatever operation you set up.
Workflow design involves configuring the new file trigger, adding workflow variables, creating a download link, and then modifying the URL as needed and attempting download. After this part of the workflow, you can set up other operations on the content of the downloaded file, such as parsing comma-separated values.
-
Configure the new file trigger (Box - New file start event).
In the Designer page:
- At the top of the designer canvas on the Designer page, click Start event to open the Start event configuration panel.
- For Connector, select Box.
-
For Event, select Box - New file.
- In the Start event dialog box, find the Source section.
- To select an existing Box connection, select the one you want from the drop-down list for Connection. If you do not have a connection, see Add a connection.
-
For Path, click the folder browse icon to navigate the folder structure in the selected connection.
- In the Start event variables section, click (Toggle add variable) to display Add start event variable.
-
Under Add start event variable, from the drop-down list for Name, select the Path variable.
-
Add workflow variables.
- Click Variables at the top of the workflow designer.
- Click to display the Add variable section.
-
For each variable indicated below, complete the Name and Value fields and then click Add.
Name
Type
Default value, if applicable
textRedirectURL Text textStatusCode Text 301
fileContent Text textHeaders
Text
-
Create a download link.
-
Drag the Box - Share file link action onto the designer canvas.
-
Click the Box - Share file link action.
- For Connection, select the same Box connection used in the start event.
- For Path, insert the variable Path.
- For Store download link, insert the variable textRedirectURL.
-
-
Implement loop logic for modifying URL and retrying download.
This procedure involves setting up the loop container, attempting file download (and obtaining status code), extracting the redirect portion, and setting the status code if no redirect.
-
Set up the loop container.
-
Drag the Start a loop action onto the canvas after the Box - Share file link action.
-
Click the Start a loop action.
- For When, insert the variable textStatusCode.
- For Operator, select equals (=).
- For Value, type 301.
- Click Add condition to save the new condition.
- Click Add condition to add a second condition.
- For When, insert the variable textStatusCode.
- For Operator, select equals (=).
- For Value, type 302.
- Click Add condition to save the second condition.
- For If __ of the following is true, select any to insert an "or" between the two conditions.
For more information on the fields, see Start a loop fields, buttons, and settings.
-
-
Attempt file download (and obtain status code).
- Drag the Call a web service action into the loop container.
- Click the Call a web service action.
-
Configure fields as follows.
Field
Value ("[]" indicates variable)
URL [textRedirectURL] Request type
HTTP Get
Response content
[fileContent]
Response headers
[textHeaders]
Response status code
[textStatusCode]
-
Extract the redirect portion of the URL.
-
Drag the Run if true action onto the canvas after the Call a web service action.
-
Click the Run if true action.
-
Configure fields as follows.
Field
Value ("[]" indicates variable)
When [textStatusCode] Operator equals (=) Value 301 - Click Add condition to save the new condition.
- Click Add condition again to add a second condition.
-
Configure fields as follows:
Field
Value ("[]" indicates variable)
When [textStatusCode] Operator equals (=) Value 302 - Click Add condition to save the second condition.
- For If __ of the following is true, select any to insert an "or" between the two conditions.
- Drag the Apply a regular expression action onto the canvas after the Run if true action.
-
Configure fields as follows:
Field
Value ("[]" indicates variable)
Input text [textHeaders] Operation Extract Pattern (?<=\"location\"\=\>\[\")[\w\d\.\:\/\-\_ ]+(?=\"\]\,) Ignore case
Yes
Store first result in
textRedirectURL
-
-
Set status code if no redirect.
-
Drag the Run if true action onto the canvas after the Apply a regular expression action.
-
Click the Run if true action.
-
Configure fields as follows:
Field
Value ("[]" indicates variable)
When [textRedirectURL] Operator is empty - Click Add condition to save the new condition.
- Drag the Set a variable value action onto the canvas after the last Run if true action.
-
Configure fields as follows:
Field
Value ("[]" indicates variable)
Variable [textStatusCode] Value 200
-
-