When automatically saving attachments from email into OneDrive, using the Power Automate Create File function, the new file will automatically overwrite the existing file. Create File does not append a serial number or otherwise handle the duplication in a lossless way. I don't see any easy way to automatically assign a unique name to new files, so that the existing ones are not overwritten.
I assume one could get the names of all the files in the folder (hundreds? thousands?), check the list for duplicate file names, and if necessary add a serial number to generate a unique name. That's a lot more Power Automate code than I am prepared to learn, write, and debug.
One can reduce the problem somewhat by prepending to the filename the time the file was received, but that results in long clunky file names, and does not successfully handle multiple attachments from the same email that just happen to have the same file name.
Is there any solution to this issue? It seems very limiting to the general usefulness of the email-to-OneDrive flow.
And a slightly larger, slightly different .docx file comes through corrupted. This does not work. I'm bagging it.
This has been putting 4 byte files into the Attachments folder. I think that there must be something broken in the initial Create File operation.
That's great, thanks. I have also tried adding a Send Email operation, Configured To Run After if the Move fails. All it does is send me an email if the move fails - not nearly as good as your solution.
Hi @Anonymous
You need to add two branches. One if the move was a success and another if it was not.
- Add another move after the first move
This left branch is in case if the first move failed
This time give a new name (maybe a datetimestamp suffix).
The second move is to rename the file along with the move.
- Select the plus sign below the original move and choose "Add a parallel branch"
Now you have the right hand side branch. Choose what you want to do in case the original move was a success.
- See the red box marked with the dotted arrow in the above screenshot on the LHS.
To achieve that click on the three dots in the second move -> Then click "Configure run after" -> Then select as below
This will tell the flow to run the LHS branch only when the first move has failed.
You can also select "is skipped" or "has timed out" depending on the needs of your project requirements.
It will be difficult for me to show the error handling here :). So you might want take a look at some videos and articles on this topic.
Hope this should get you going.
If there is already a document with the same name in the Attachments folder, then the Move Or Rename (Overwrite = No) does not move the file.
{"statusCode":400,"headers":{"Pragma":"no-cache","Transfer-Encoding":"chunked","x-ms-request-id":"5ed77b20-025d-49e6-8aa1-10d91d914c59","Timing-Allow-Origin":"*","x-ms-apihub-cached-response":"true","Cache-Control":"no-cache","Date":"Tue, 05 Oct 2021 03:41:13 GMT","X-AspNet-Version":"4.0.30319","X-Powered-By":"ASP.NET","Content-Type":"application/json","Expires":"-1","Content-Length":"187"},"body":{"status":400,"message":"Destination file '/Attachments/Document.docx' already exists. To overwrite this file, set overwrite to 'true'.","source":"api.connectorp.svc.ms"}}
Unfortunately, if the Power Automate window is not open, and I don't look in the Attachments/&temp subfolder to see if there is a document stuck there, then I won't know about the failure.
The two Move functions differ only in how the file to be moved is referenced. Move or rename a file uses the file ID as a handle, whereas Move or rename a file using a path uses the file path.
Hi @Anonymous
Check the outputs of the move action and see whether it gives output dynamic content that says move was a success or not.
I sent two messages with the same attachments. The first time, the file was moved from the /Attachments/&temp/ subfolder to the /Attachments/ folder. The second time, the file was not moved; it was left in the /Attachments/&temp/ subfolder. The move without overwrite instruction did not overwrite the first file, but there was no other action such as an error message.
Hi @Anonymous
The move simply did not occur; the file was left in the temp folder. The flow failed silently.
The move worked out for me smoothly.
So please double check on path.
I guess I got confused. You wrote:
Be noted that if a file with the same name already exists there then this action shows the below message.
So handle it as per your requirements.
I interpreted "handle it" as manually dealing with the error when the "below message" was shown. However, I never saw the "below message" or any other indication of trouble. The move simply did not occur; the file was left in the temp folder. The flow failed silently.
I agree about the date / time stamp. If I inserted a delay of 1 second in the Apply To Each loop, no two file names would ever be the same. I don't know how to do that, but no doubt there must be a way.
The resulting file names would still be long and ugly. Making all file names that way is not a satisfactory solution, but maybe it is a useful way to handle duplications. If the Move with no overwrite fails, prepending the date/time stamp before the file name would make it unique. There would have to be an error handling routine; I don't know how to catch the error.
WarrenBelz
146,743
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
66,079
Most Valuable Professional