cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
rsymmons
Resolver I
Resolver I

Unable to reference fields outside of apply to each shell, cognito forms

I'm using Cognito forms as a file upload web form to import documents into SharePoint but when I add the file upload fields onto the flow, they are automatically put into a apply to each shell. I have several file upload fields that I want to be able to link to an approval step after the files have been submitted but when they are within the shell, I cannot link to the fields outside of the apply to each. 

flow.png

I'd like to add a new step here, but I'm unable to reach the newly created file in SharePoint as it's been created within the apply to each shell.

 

Any help greatly appreciated.

 
1 ACCEPTED SOLUTION

Accepted Solutions

Hi @rsymmons 

From your message on deleting SharePoint files while trying to reference them inside the loop.

 

Please try and follow my POC:

A summary:

- I am Initializing an array variable with []

- Next we use the Get file properties under the Create file inside the loop

- Now append the 'Identifier' to the array variable

- Now outside the loop you can create another loop and use the Array Variable as the input

pic1.png

 

pic2.png

 

pic3.png

 

 

—Josh
If you like my post please hit the "Thumbs Up" -- If my post solved your issue please "Mark as a Solution" to help others

 


Did I answer your question? Mark my post as a solution!

If you like my post please hit the Thumbs Up


Proud to be a Flownaut!


Check out my blog for Power Automate tips,
tricks, and guides
FlowAltDelete





View solution in original post

9 REPLIES 9
Jcook
Super User
Super User

Hello,
Yes you won’t be able to reference anything inside the loop without being in the loop.

Couple of questions:
Is there only one attachment in the form? Or can there be multiple attachments?

Depending on the answer to my above question:
Only one attachment - you can follow my blog post since there is only one attachment. Use the same expressions in my post to bypass the apply to each loop:
https://powerusers.microsoft.com/t5/Power-Automate-Community-Blog/Bypass-Apply-to-each-loop-on-singl...

If you still need to use the loop, or multiple attachments. You can follow this logic:
Have an array variable initialize as []
Append the File identifier from the create file action to the array
Now outside the loop use a Compose action, use the expression split()
In the () our the dynamic content of the array and split on a ,
Example:
split(variables(‘myarray’),’,’)
Now use another apply to each loop and put the outputs of the Compose as the loop input
Now you have the file identifier of each file created

Lastly, you can use a List folder action and use the File identifier to get all details of the file created.

If you need help let me know.

—Josh
If you like my post please hit the "Thumbs Up" -- If my post solved your issue please "Mark as a Solution" to help others

Did I answer your question? Mark my post as a solution!

If you like my post please hit the Thumbs Up


Proud to be a Flownaut!


Check out my blog for Power Automate tips,
tricks, and guides
FlowAltDelete





Hi Josh,

 

Thanks for your response, I'll give this a try tomorrow and see how I get on. 

 

Each file upload field only allows one file attachment however there are several file upload fields in total.

 

Cheers,

Rob

I've given this a go but not sure I follow the instructions, sorry this isn't quite my thing! 

 

I have 7 "file name" fields and 7 file upload fields to build into this flow. I need to create a copy of the uploaded file in SharePoint so I can create a "link to file" in approvals for our staff to review the doc (they don't have access to cognito forms). After the submission is approved the files are then relocated to another part of SharePoint, under a new heading (folder). I think I'll also need conditions built in to prevent errors when files are not uploaded. Do you think this is possible to achieve in Flow? 

 

I've managed to use a variable in a slightly different way to get the name part of the "apply to each" working, but for file content it missed a small part of the code so the files were unreadable.

 

Top is the variable version of file content code, bottom is the apply to each version (bottom works):

variable difference.png

 

Hello,
Does this blog help:
https://www.ohthreesixtyfive.org/2018/06/microsoft-flow-cognito-forms-error-uploading-form-attachmen...

—Josh
If you like my post please hit the "Thumbs Up" -- If my post solved your issue please "Mark as a Solution" to help others

Did I answer your question? Mark my post as a solution!

If you like my post please hit the Thumbs Up


Proud to be a Flownaut!


Check out my blog for Power Automate tips,
tricks, and guides
FlowAltDelete





This method still wraps the field in a apply to each shell. I'm able to create the file just fine within the shell, it's only when I used an initialize variable and then an append so I can pull the file outside of the shell that I run into issues. 

 

Variable.png

 

Hi,
You can move the create file action inside the loop. You won’t be able to append multiple files together to create a file.

Why are you trying to avoid the apply to each loop?

—Josh
If you like my post please hit the "Thumbs Up" -- If my post solved your issue please "Mark as a Solution" to help others

Did I answer your question? Mark my post as a solution!

If you like my post please hit the Thumbs Up


Proud to be a Flownaut!


Check out my blog for Power Automate tips,
tricks, and guides
FlowAltDelete





I guess I'm trying to avoid the loop because I'm unable to access the files using the approval process outside of these loops. I also need to on approval move these all of these files to a new location. This is what we're trying to achieve:

 

  1. Our volunteers fill out their expenses using cognito forms
  2. Their receipts are uploaded to Cognito forms
  3. The files from Cognito are stored in a sandbox area in SharePoint
  4. An approval process is created that groups together each individual's files in one approval, links to the sandbox files are in the item link part of approvals
  5. One of our volunteer team members checks over the files (volunteers tend to get this wrong a lot) and either approves or rejects the submission
  6. If approved the files are copied to our SP site, under a new folder for the volunteer
  7. The form data goes into an Excel spreadsheet table

 

The only part that seems to be preventing me from being able to achieve the above is the inability to access the files created in the sandbox area of sharepoint outside of each of the loops otherwise we would be creating 7 approvals per individual. 

 

Regards,

Rob

Hi @rsymmons 

From your message on deleting SharePoint files while trying to reference them inside the loop.

 

Please try and follow my POC:

A summary:

- I am Initializing an array variable with []

- Next we use the Get file properties under the Create file inside the loop

- Now append the 'Identifier' to the array variable

- Now outside the loop you can create another loop and use the Array Variable as the input

pic1.png

 

pic2.png

 

pic3.png

 

 

—Josh
If you like my post please hit the "Thumbs Up" -- If my post solved your issue please "Mark as a Solution" to help others

 


Did I answer your question? Mark my post as a solution!

If you like my post please hit the Thumbs Up


Proud to be a Flownaut!


Check out my blog for Power Automate tips,
tricks, and guides
FlowAltDelete





View solution in original post

Thanks a million that seems to have done it!

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Users online (1,341)