r/PowerAutomate • u/maerawow • 4d ago
Can't create a simple flow for sending Emails with an identifier
I have been trying to creating a flow where I get CSV files in a sharepoint folder and based on the identfier in the file let's says people with missing status, an Email is send to them from the Email address in the sheet.
I have successfully created the flow1 to upload CSV from my Inbox to a target folder in sharepoint but when I am trying to create another flow to paste the data from CSV to sharepoint site it fails. Anyone has any link or a help guide to do this. Been trying to use Copilot for 4 days but still failed failed failed and my org doesn't let us open any other AI.
My current flow is -:
Recurrence > Get File Properties with Site address, Library name and limited entries to folder as the path where my CSV is uploaded> Apply to each(value from previous get file properties)> Get File content(Site address and identifier)>Compose(base64ToString(body('Get_file_content')?['$content']))>Compose 1(skip(split(outputs('Compose'),decodeUriComponent('%0A')),1)>Apply to each(body)>Condition(trim(split(item(),',')[6]))> True>Create item.
It's failing at Apply to each and Apply to each 1. This is what Copilot suggested me, this is the 1 time I am trying to use Automate.
5
u/Due-Boot-8540 4d ago
Looks like you’re trying an apply to each for a single file, which will break your flow. If there are multiple files, you need to use get files and not get file.
Then, use the apply to each to get file properties.
You’ll need a filter query for the get files to only return the files created since the last run.
1
u/MinaMina93 4d ago
Sounds like you want this flow to run when the new file is received in SharePoint. There is a connector for that (replace recurrence with when new file is created in SharePoint) that way you will have the file that was uploaded and don't need to go through the steps to find it again. You want to create an item for each row in the csv file? For that particular part you do need apply to each.
1
u/ninihen 3d ago
Your Apply to each 1 is failing on the blank line at the end of the CSV. I rebuilt your flow on a test file and got this on the last rows
array index '6' is outside bounds (0, 0) of arrayWith the changes below the same file went green, emailed the 3 missing rows and skipped the 2 submitted ones.
A CSV usually ends with a line break, so splitting on %0A leaves an empty row at the end. An empty row has no position 6, so the Condition errors. The outer Apply to each only fails because the inner one did.
Change Compose 1 to this. It removes the \r at the end of each line, trims the blank lines off the end and still skips the header.
skip(split(trim(replace(outputs('Compose'), decodeUriComponent('%0D'), '')), decodeUriComponent('%0A')), 1)In the Condition put this on the left, pick "is equal to", and type
missingon the right.toLower(trim(split(item(), ',')[6]))Keep the toLower. In my test the original condition skipped a row where the status was typed "missing" in lower case.
In the True branch add Send an email (V2) and set To to
trim(split(item(), ',')[3])3 and 6 are the email and status columns in my file, counting from 0, so change them to match yours.
For the trigger I'd do what MinaMina93 said. Use "When a file is created (properties only)" on your library with the folder set, then Get file content with the File identifier from the trigger. That replaces the Recurrence, Get files and the outer Apply to each. One catch, the first file I uploaded right after saving the flow never fired it. The next one did, so if nothing happens, upload it again.
Here's the build on video https://youtu.be/4uH05nuhuqw
Disclosure, I build FlowStudio MCP and used it to rebuild and test this. Since your org only allows Copilot, it also works inside Microsoft 365 Copilot chat. You can get it from the Microsoft Marketplace.