@Lablirows The parallel Apply to Each actions are unnecessary and inefficient.
Manually Trigger Flow (while building)
While you are building your flow I would recommend you use a Manual trigger. This will help speed up your flow building process and allow you to quickly test at each stage of your flow. Tip: Always rename your actions to keep things organized!
Review a previous flow run and copy the Form Id to your clipboard and take note of the Response Id.

Insert that into the Get response details action of your flow.

Create an Array
Because you have multiple onsite details that you'd like to loop through. It's best to create an Array that can be looped through. For more tips on using the Apply to Each action—refer to this recent YT Tutorial I uploaded.
By creating an array you can use a Filter Array action to pull out the items that only contain values in the location and date fields. For more information on how to use the Filter Array action—refer to this YT Tutorial.
A basic array looks like this.
[
{
"item 1"
},
{
"item 2"
},
{
"item 3"
}
]
For your array, treat each onsite option as an item. The key (eg. "onsite", "location", "date" can be customized to your requirements. You'll just need to note these keys for use later.
The content (eg. Onsite 1, Onsite 2, Onsite 3) is what will be outputted when you reference the key in an expression. This can also be customized to your requirements.
[
{
"onsite": "Onsite 1",
"location": [insert dynamic content for location],
"date":[insert dynamic content for date]
},
{
"onsite": "Onsite 2",
"location": [insert dynamic content for location],
"date":[insert dynamic content for date]
},
{
"onsite": "Onsite 3",
"location": [insert dynamic content for location],
"date":[insert dynamic content for date]
}
]

Run a test. Any dynamic fields that are empty will display "". In this example below, the Onsite 2 and Onsite 3

Filter Array
Add a Filter Array action to your flow. You'll use this action to filter out items that do not have an empty location and empty date.
In the From field, insert the Outputs from the Compose action above (the one that has your array). Click on Edit in advance mode.

You'll need to use an expression. Do not try to type into this field. You will need to use a text editor to compose your expression first, then copy/paste it into the field. Refer to this section of my YT Tutorial on how to use multiple conditions in the Filter Array action and why you can't type into that field.
The expression you will need to use will look something like this. Note: This may be a bit different based on your array keys.
@and(not(equals(item()?['location'], '')), or(not(equals(item()?['date'], '')), equals(item()?['date'], '')))
Run a test. As you can see the inputs show 3 items in the array. However after the array has been filtered, only a single item has returned.

Check the Count of Items Returned
Whenever I use a Filter Query in a Get Items action, I always like to return the count of items returned in a Compose action. This is helpful when building a flow and can also be used to troubleshoot your flow.
Insert a Compose action. Add an Expression. Use the length() function.

Select the Dynamic content tab and insert the value dynamic content from the Get Items action into the length() function.

Run a test.
Add a Condition
Add a Condition action to your flow to check the number of items returned. If no items have returned, do nothing, The rest of your actions can go into the YES branch.

Apply to Each Item
Add an Apply to Each action and insert the Body outputs from the Filter Array action. This Apply to Each action will loop through each item from your array that has been filtered (aka the outputs from the Filter Array action).

Get the Dynamic Content
For more information on how to access dynamic content from a Filter Array action—refer to this section of my YT Tutorial. The Compose actions are optional—however they can help with troubleshooting and it's easy to confirm the dynamic content before using it in a Create Item action.
Use the item() function. Insert the following into the Expression field.

In between the single quotes enter the dynamic content key. For this example, I'll use onsite.


Repeat these steps for each key.

Run a test. Verify the outputs of each Compose action.

Create Item
You can now insert the Create Item action and use the outputs from each compose action in the appropriate fields.

Save As + Replace Trigger
Once you've tested your flow and confirmed everything works, create a copy of your flow and replace the trigger. I would recommend keeping the manually triggered flow for testing purposes. This will be handy should your form change in the future or if you are running to any issues with the automatically triggered flow.

Replace the response ID with the Response id dynamic content from the flow trigger.

Hope this helps!
If I helped you solve your problem—please mark my post as a solution ✅. Consider giving me a 👍 if you liked my response!
|