SOLVED

Power Automate Sharepoint file Copy not keeping the created by

%3CLINGO-SUB%20id%3D%22lingo-sub-1626026%22%20slang%3D%22en-US%22%3EPower%20Automate%20Sharepoint%20file%20Copy%20not%20keeping%20the%20created%20by%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1626026%22%20slang%3D%22en-US%22%3E%3CP%3ELike%20many%20I'm%20trying%20to%20move%20my%20SharePoint%20Designer%20Workflows%20to%20Power%20Automate.%20I%20ran%20into%20a%20problem%20with%20copying%20a%20file%20from%20one%20SharePoint%20library%20to%20another.%20I%20use%202%20libraries%2C%20one%20where%20the%20users%20can%20add%20a%20file%2C%20then%20the%20file%20is%20copied%20to%20an%20archive%20library%20where%20they%20can%20not%20make%20any%20changes.%20Currently%20I'm%20using%20a%20workflow%20in%20impersonation%20mode%20where%20when%20a%20file%20is%20changed%20it%20copies%20the%20file%20to%20the%20archive%20library%20overwriting%20what%20is%20there.%20I've%20mimicked%20this%20in%20Power%20Automate%20using%20a%20created%20%2F%20modified%20trigger%20which%20works%20but%20it%20puts%20me%20as%20the%20created%20by%20when%20I%20would%20like%20the%20actual%20user%20who%20created%20it.%20Is%20there%20anyway%20around%20this%3F%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1626026%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMicrosoft%20Flow%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerApps%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1628070%22%20slang%3D%22en-US%22%3ERe%3A%20Power%20Automate%20Sharepoint%20file%20Copy%20not%20keeping%20the%20created%20by%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1628070%22%20slang%3D%22en-US%22%3ECreated%20by%20is%20always%20whatever%20account%20added%20the%20file%2C%20this%20cannot%20be%20changed%2C%20modified%20should%20be%20retained%20however.%20The%20only%20exception%20I've%20seen%20is%20bulk%20migration%20tools%20utilizing%20the%20bulk%20import%20methods.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1628085%22%20slang%3D%22en-US%22%3ERe%3A%20Power%20Automate%20Sharepoint%20file%20Copy%20not%20keeping%20the%20created%20by%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1628085%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F869%22%20target%3D%22_blank%22%3E%40Chris%20Webb%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20for%20your%20response.%20With%20the%20workflow%20and%20the%20impersonation%20step%2C%20the%20copied%20file%20would%20keep%20the%20created%20by%20and%20the%20modified%20would%20change%20to%20the%20impersonation%20account.%3C%2FP%3E%3CP%3ENow%20with%20flow%20it%20is%20changing%20both%20the%20created%20by%20and%20the%20modified%20by%20to%20the%20account%20that%20created%20the%20flow%20loosing%20the%20meta%20data%20I%20need.%3C%2FP%3E%3CP%3EIs%20there%20anyway%20to%20change%20this%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1628497%22%20slang%3D%22en-US%22%3ERe%3A%20Power%20Automate%20Sharepoint%20file%20Copy%20not%20keeping%20the%20created%20by%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1628497%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F163398%22%20target%3D%22_blank%22%3E%40Sean%20Kuchle%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOk%2C%20so%20I%20can't%20find%20anywhere%20that%20says%20this%20is%20possible%20or%20how%20to%20do%20it%2C%20but%20I%20just%20figured%20it%20out%2C%20at%20least%20it%20works%20for%20me%20going%20cross%20site.%20So%20the%20trick%20is%20to%20utilize%20the%20built%20in%20move%20to%20command%20via%20REST%20API.%20There%20is%20a%20hidden%20little%20property%20on%20it%20that%20acts%20like%20a%20move%20but%20retains%20the%20source%20since%20copy%20doesn't%20retain%20metadata%20but%20move%20to%20command%20will.%20So%20this%20seems%20to%20work%2C%20here%20is%20a%20Screen%20of%20my%20test%20flow.%20I'll%20also%20paste%20the%20Body%20text%20down%20below%20so%20you%20can%20copy%20and%20paste%2C%20but%20it's%20actually%20pretty%20simple%20once%20you%20figure%20out%20all%20this%20undocumented%20stuff%20like%20the%20Conflictname%20behavior%20which%20I%20just%20guessed%20at%20to%20find%20the%20right%20number%20to%20override%20the%20name.%20You%20can%20also%20change%20that%20to%20a%202%20if%20you%20want%20to%20generate%20a%20new%20file%20for%20each%20update%20instead%2C%20or%200%20to%20do%20nothing%20if%20one%20exists.%20Anyway%20hope%20this%20works%20for%20you%2C%20not%20sure%20how%20it'll%20work%20with%20files%20already%20open%20for%20editing%20but%20hopefully%20it%20still%20copies%20and%20doesn't%20error%20when%20locked%20for%20editing%20otherwise%20I%20don't%20think%20it'll%20be%20possible.%20You%20can%20get%20status%20of%20the%20job%20etc.%20to%20do%20retries%20if%20that's%20the%20case%20but%20that's%20outside%20my%20time%20to%20spend%20on%20this%20limitations%20%3A).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22copy%20file.PNG%22%20style%3D%22width%3A%20630px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F216090i2B1D61AB26B1F612%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22copy%20file.PNG%22%20alt%3D%22copy%20file.PNG%22%20%2F%3E%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3EAPI%3A%26nbsp%3B_api%2Fsite%2FCreateCopyJobs%3C%2FP%3E%0A%3CP%3EBody%3A%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%7B%20%3CBR%20%2F%3E%22exportObjectUris%22%3A%5B%20%3CBR%20%2F%3E%22Link%20to%20Item%20from%20Get%20File%20Properties%20Step%20goes%20here%22%3CBR%20%2F%3E%5D%2C%3CBR%20%2F%3E%22destinationUri%22%3A%22%3CA%20href%3D%22https%3A%2F%2FYour_Tenant.sharepoint.com%2Fsites%2FYourSite%2FYourLibrary_NoSlash_at_end%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2FYour_Tenant.sharepoint.com%2Fsites%2FYourSite%2FYourLibrary_NoSlash_at_end%3C%2FA%3E%22%2C%3CBR%20%2F%3E%22options%22%3A%7B%20%3CBR%20%2F%3E%22IgnoreVersionHistory%22%3Atrue%2C%3CBR%20%2F%3E%22IsMoveMode%22%3Atrue%2C%3CBR%20%2F%3E%22MoveButKeepSource%22%3Atrue%2C%3CBR%20%2F%3E%22NameConflictBehavior%22%3A1%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%7D%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1628502%22%20slang%3D%22en-US%22%3ERe%3A%20Power%20Automate%20Sharepoint%20file%20Copy%20not%20keeping%20the%20created%20by%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1628502%22%20slang%3D%22en-US%22%3EOps%2C%20sorry%2C%20also%20the%20First%20trigger%20would%20obviously%20your%20%22When%20created%20or%20modified%22%20instead%20to%20automate%20it%2C%20I%20had%20for%20selected%20for%20testing%20purposes.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1628644%22%20slang%3D%22en-US%22%3ERe%3A%20Power%20Automate%20Sharepoint%20file%20Copy%20not%20keeping%20the%20created%20by%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1628644%22%20slang%3D%22en-US%22%3EWell%2C%20I%20don't%20understand%20why%2C%20but%20this%20just%20all%20the%20sudden%20stopped%20working%20and%20says%20bad%20gateway%2C%20but%20it%20was%20working%20just%20fine%20up%20till%20I%20messaged%20you.%20Not%20sure%20if%20my%20testing%20caused%20an%20issue%20or%20not%2C%20but%20give%20it%20a%20go%20and%20see%20if%20it%20works%20for%20you.%20I'm%20going%20to%20give%20this%20some%20time%20cause%20I%20think%20something%20is%20up%20with%20the%20API%20or%20something%20right%20now%20cause%20all%20I%20did%20was%20change%20my%20views%20to%20not%20show%20folders%20and%20tried%20to%20run%20one%20and%20it%20stopped%20working%20after%20that%20even%20after%20changing%20the%20views%20back%2C%20so%20something%20in%20that%20transition%20upset%20the%20API%20on%20my%20end%20so%20don't%20do%20that%20with%20your%20view%20%3B).%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1628954%22%20slang%3D%22en-US%22%3ERe%3A%20Power%20Automate%20Sharepoint%20file%20Copy%20not%20keeping%20the%20created%20by%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1628954%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F869%22%20target%3D%22_blank%22%3E%40Chris%20Webb%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20so%20much%20for%20your%20help%20and%20that%20seems%20like%20a%20neat%20hack%20but%20I%20am%20getting%20the%20%22BadGateway%22%20errors%20as%20well.%20It%20says%202%20retries%20occurred.%3C%2FP%3E%3CP%3EJust%20to%20make%20sure%20I%20didn't%20miss%20anything%20here%20is%20the%20flow%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Example-9-2-2020.png%22%20style%3D%22width%3A%20620px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F216116iAA2333A5081F2888%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20title%3D%22Example-9-2-2020.png%22%20alt%3D%22Example-9-2-2020.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1628971%22%20slang%3D%22en-US%22%3ERe%3A%20Power%20Automate%20Sharepoint%20file%20Copy%20not%20keeping%20the%20created%20by%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1628971%22%20slang%3D%22en-US%22%3EYeah%20I'm%20literally%20getting%20the%20same%20thing%2C%20it%20just%20stopped%20working%20out%20of%20the%20blue%2C%20annoying%20cause%20I%20had%20figured%20this%20out%20and%20now%20it%20just%20quit%20for%20no%20reason%20it%20seems.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1629066%22%20slang%3D%22en-US%22%3ERe%3A%20Power%20Automate%20Sharepoint%20file%20Copy%20not%20keeping%20the%20created%20by%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1629066%22%20slang%3D%22en-US%22%3EWow%20figured%20it%20out%2C%20I%20don't%20know%20what%20changed%20with%20my%20columns%20by%20enabling%20that%20view%2C%20but%20add%20this%20in.%20%3CBR%20%2F%3E%22NameConflictBehavior%22%3A1%2C%3CBR%20%2F%3E%22AllowSchemaMismatch%22%3Atrue%20%3CBR%20%2F%3E%3CBR%20%2F%3EAt%20the%20end%2C%20make%20sure%20you%20put%20that%20comma%20after%20the%201%20in%20first%20existing%20line%2C%20then%20add%20the%20allowschemamismatch%2C%20this%20solved%20it%20for%20me%20and%20it's%20working%20again.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1629292%22%20slang%3D%22en-US%22%3ERe%3A%20Power%20Automate%20Sharepoint%20file%20Copy%20not%20keeping%20the%20created%20by%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1629292%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F869%22%20target%3D%22_blank%22%3E%40Chris%20Webb%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThat%20worked%20great!%20Thank%20you%20so%20much%20for%20your%20help!%3C%2FP%3E%3CP%3EI'm%20just%20curious%20is%20there%20anywhere%20I%20can%20go%20to%20learn%20more%20about%20these%20Api%20calls%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1629414%22%20slang%3D%22en-US%22%3ERe%3A%20Power%20Automate%20Sharepoint%20file%20Copy%20not%20keeping%20the%20created%20by%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1629414%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F163398%22%20target%3D%22_blank%22%3E%40Sean%20Kuchle%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESweet!%20If%20you%20want%20to%20pull%20across%20version%20history%20you%20can%20by%20changing%20that%20flag%20false.%20Now%20I%20don't%20know%20if%20doing%20this%20resets%20your%20versions%20either%2C%20that%20could%20be%20a%20side%20effect%2C%20so%20you%20might%20need%20to%20test%20that%2C%20and%20if%20someone%20has%20a%20file%20open%20etc.%20Hopefully%20it%20just%20leaves%20existing%20file%20and%20copies%20one%20over%20using%20move%20method.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAnyway%2C%20I%20just%20googled%20stuff%20up%20cause%20I've%20had%20to%20use%20REST%20api%20calls%20to%20rename%20a%20file%20and%20thought%20there%20would%20be%20a%20copy%20one%2C%20which%20there%20is%20but%20it%20doesn't%20retain%20the%20meta%20either.%20Then%20I%20stumped%20across%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsharepoint%2Fdev%2Fapis%2Fspod-copy-move-api%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ethis%20docs%20article%20for%20the%20CreateCopyJob%3C%2FA%3Es%20and%20a%20%3CA%20href%3D%22https%3A%2F%2Fblog.velingeorgiev.com%2Fcreatecopyjobs-api-copy-move-SharePoint-files-folders%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Eblog%3C%2FA%3E%20about%20using%20it%20for%20copying%20files%2C%20but%20I%20read%20over%20the%20docs%20and%20happen%20to%20notice%20that%20property%20and%20came%20up%20with%20the%20idea%20of%20using%20that%2C%20built%20it%20and%20tested%20and%20figured%20out%20it%20does%20retain%20that%20information%20like%20a%20move!%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

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?

Thanks

10 Replies
Highlighted
Created by is always whatever account added the file, this cannot be changed, modified should be retained however. The only exception I've seen is bulk migration tools utilizing the bulk import methods.
Highlighted

@Chris Webb 

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?

Highlighted
Best Response confirmed by Sean Kuchle (Occasional Contributor)
Solution

@Sean Kuchle 

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 :).

 

copy file.PNG

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
}
}

Highlighted
Ops, sorry, also the First trigger would obviously your "When created or modified" instead to automate it, I had for selected for testing purposes.
Highlighted
Well, 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 ;).
Highlighted

@Chris Webb 

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

Example-9-2-2020.png

Highlighted
Yeah 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.
Highlighted
Wow figured it out, I don't know what changed with my columns by enabling that view, but add this in.
"NameConflictBehavior":1,
"AllowSchemaMismatch":true

At the end, make sure you put that comma after the 1 in first existing line, then add the allowschemamismatch, this solved it for me and it's working again.
Highlighted

@Chris Webb 

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?

Highlighted

@Sean Kuchle 

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!