Forum Discussion
Power Automate Sharepoint file Copy not keeping the created by
- Sep 02, 2020
Ok, so I can't find anywhere that says this is possible or how to do it, but I just figured it out, at least it works for me going cross site. So the trick is to utilize the built in move to command via REST API. There is a hidden little property on it that acts like a move but retains the source since copy doesn't retain metadata but move to command will. So this seems to work, here is a Screen of my test flow. I'll also paste the Body text down below so you can copy and paste, but it's actually pretty simple once you figure out all this undocumented stuff like the Conflictname behavior which I just guessed at to find the right number to override the name. You can also change that to a 2 if you want to generate a new file for each update instead, or 0 to do nothing if one exists. Anyway hope this works for you, not sure how it'll work with files already open for editing but hopefully it still copies and doesn't error when locked for editing otherwise I don't think it'll be possible. You can get status of the job etc. to do retries if that's the case but that's outside my time to spend on this limitations :).
API: _api/site/CreateCopyJobsBody:
{
"exportObjectUris":[
"Link to Item from Get File Properties Step goes here"
],
"destinationUri":"https://Your_Tenant.sharepoint.com/sites/YourSite/YourLibrary_NoSlash_at_end",
"options":{
"IgnoreVersionHistory":true,
"IsMoveMode":true,
"MoveButKeepSource":true,
"NameConflictBehavior":1
}
}
Thank you for your response. With the workflow and the impersonation step, the copied file would keep the created by and the modified would change to the impersonation account.
Now with flow it is changing both the created by and the modified by to the account that created the flow loosing the meta data I need.
Is there anyway to change this?
Ok, so I can't find anywhere that says this is possible or how to do it, but I just figured it out, at least it works for me going cross site. So the trick is to utilize the built in move to command via REST API. There is a hidden little property on it that acts like a move but retains the source since copy doesn't retain metadata but move to command will. So this seems to work, here is a Screen of my test flow. I'll also paste the Body text down below so you can copy and paste, but it's actually pretty simple once you figure out all this undocumented stuff like the Conflictname behavior which I just guessed at to find the right number to override the name. You can also change that to a 2 if you want to generate a new file for each update instead, or 0 to do nothing if one exists. Anyway hope this works for you, not sure how it'll work with files already open for editing but hopefully it still copies and doesn't error when locked for editing otherwise I don't think it'll be possible. You can get status of the job etc. to do retries if that's the case but that's outside my time to spend on this limitations :).
API: _api/site/CreateCopyJobs
Body:
{
"exportObjectUris":[
"Link to Item from Get File Properties Step goes here"
],
"destinationUri":"https://Your_Tenant.sharepoint.com/sites/YourSite/YourLibrary_NoSlash_at_end",
"options":{
"IgnoreVersionHistory":true,
"IsMoveMode":true,
"MoveButKeepSource":true,
"NameConflictBehavior":1
}
}
- Sep 02, 2020Ops, sorry, also the First trigger would obviously your "When created or modified" instead to automate it, I had for selected for testing purposes.
- gregbutler_20Jan 19, 2022Copper Contributor
ChrisWebbTechI have a question. Is there another number for NameConflict behavior? So, I see that 1 is replace and 2 is copy, but what if I want to ignore if a file with the same name is already there? Is there an option for that?
- Sep 02, 2020Well, I don't understand why, but this just all the sudden stopped working and says bad gateway, but it was working just fine up till I messaged you. Not sure if my testing caused an issue or not, but give it a go and see if it works for you. I'm going to give this some time cause I think something is up with the API or something right now cause all I did was change my views to not show folders and tried to run one and it stopped working after that even after changing the views back, so something in that transition upset the API on my end so don't do that with your view ;).
- Sean KuchleSep 02, 2020Brass Contributor
Thank you so much for your help and that seems like a neat hack but I am getting the "BadGateway" errors as well. It says 2 retries occurred.
Just to make sure I didn't miss anything here is the flow
- Sep 02, 2020Yeah I'm literally getting the same thing, it just stopped working out of the blue, annoying cause I had figured this out and now it just quit for no reason it seems.
- LeonaHoffmannMay 22, 2024Copper Contributor
Hi ChrisWebbTech i hope you're doing great! I tried to use your template but unfortunately it doesn't work with the newer actions. May I ask you to make a new version for your template since I'm no Power Automate specialist? Thank you!