Hello. I have a flow in which users load information with a MS Forms, it then drops into an array of folders in SharePoint, and what I want to do is attach them in an e mail that will be sent to a bot that analyses its contents. The problem is that the bot requires the files to be named in a specific way, and MS Forms adds the tag of the user into the name of the file, so I tried changing the names of the files directly on SharePoint, but since they are all now named the same the flow does not attach the correct information. So, is there a way to use the user tag to pull the documents and before attaching them to the email changing their names without altering the files in Sharepoint?
Hi @pepeHR
You could refer the below sample for pulling the files from the folder and rename the file name when storing the file details in a variable. Finally, we will pass the variable in the attachment parameter of send an email action.
1. Firstly, initialize a variable 'emailAttachments' of type array that will hold the file details (file name & content bytes):
2. Next, add Get files action to get the files from the folder.
You may change the parameter as per your need. here, I have also used filter query to limit the search to files:
FSObjType eq 0
3. Add "Apply to each" action & pass the value output from Get files action. Inside the block, add "Get file content" & pass identifier from the get files action:
Continue inside "Apply to each" action block, add "Append to array variable" action to add each file information in the variable:
The json used in "Value" parameter:
{
"name":@{concat('customname','.',last(split(item()?['{FilenameWithExtension}'],'.')))},
"contentBytes":@{body('Get_file_content')}
}
In the above json, name stores the file name, so you may modify it as per your need. This name will be used name of the attachment in the email.
4. Now, add "Send an email" action and click the button as highlighted in the below screenshot:
Pls note that this action should be added after the apply to each action, not inside the apply to each block.
Now, set the variable in the "Attachments" parameter as shown below:
If this helps & solves your problem, please remember to give a 👍 and accept my solution as it will help others in the future.
Thanks