09-01-2020 12:15 PM
09-01-2020 12:15 PM
Like many I'm trying to move my SharePoint Designer Workflows to Power Automate. I ran into a problem with copying a file from one SharePoint library to another. I use 2 libraries, one where the users can add a file, then the file is copied to an archive library where they can not make any changes. Currently I'm using a workflow in impersonation mode where when a file is changed it copies the file to the archive library overwriting what is there. I've mimicked this in Power Automate using a created / modified trigger which works but it puts me as the created by when I would like the actual user who created it. Is there anyway around this?
09-02-2020 08:29 AM
09-02-2020 08:44 AM
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?
09-02-2020 10:48 AMSolution
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 :).
"Link to Item from Get File Properties Step goes here"
09-02-2020 10:52 AM
09-02-2020 11:21 AM
09-02-2020 12:52 PM
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
09-02-2020 12:55 PM
09-02-2020 01:10 PM
09-02-2020 01:43 PM
That worked great! Thank you so much for your help!
I'm just curious is there anywhere I can go to learn more about these Api calls?
09-02-2020 02:17 PM
Sweet! If you want to pull across version history you can by changing that flag false. Now I don't know if doing this resets your versions either, that could be a side effect, so you might need to test that, and if someone has a file open etc. Hopefully it just leaves existing file and copies one over using move method.
Anyway, I just googled stuff up cause I've had to use REST api calls to rename a file and thought there would be a copy one, which there is but it doesn't retain the meta either. Then I stumped across this docs article for the CreateCopyJobs and a blog about using it for copying files, but I read over the docs and happen to notice that property and came up with the idea of using that, built it and tested and figured out it does retain that information like a move!