Kirk Liemohn is a Principal Software Engineer at ThreeWill. He has over 20 years of software development experience with most of that time spent in software consulting.
It must be possible
I recently found myself in a dilemma where I needed to update the Created, Created By, Modified, and Modified By fields for SharePoint list and library items in SharePoint Online. I had read in the past that some of these couldn’t be changed via CSOM, but I had seen migration tools do this when migrating to SharePoint Online, so I knew this must be possible.
Either my Google/Bing Foo was not good that day or there were just too many people out there saying it wasn’t possible, so I decided to figure it out for myself. It took a little trial and error, so I decided I should write it up in a blog post.
How to approach
The short answer is to look at the source further. The main tricks I needed to deal with were:
- When specifying the Created By (Author) or Modified By (Editor) user, I could not use the FieldUserValue object. Instead, I had to hand-craft it by concatenating the hidden user information list item ID and the fully qualified login name (e.g., “22;#i:0#.f|membership|[email protected]”).
- For some reason, you can set the Created By user (Author) just fine with list items. However, if you want to set the Created By user on library items, you need to also set the Modified By user or the change won’t stick.
- If you want to do this covertly, there are two extra steps to consider:
- To prevent creating a new version in version history, you may need to turn off version history before making the update and turn it back on afterward.
- To prevent updating the modified date, you need to set the modified date to the current modified date value. Otherwise, it will get updated to the current date.
8 Comments
Austin Ryan
Thanks for the great post! I have a question about it, so if you could follow up with me when you receive this comment that would be great.
Shafqat Nawaz Balouch
Thanks again for the great post! I faced the similar situation but was not updating the Author column in document set, I made some changes and used PnP commands to achieve similar required. http://shafqat-balouch.blogspot.com/2017/01/office-365-sharepoint-online-updating.html?spref=tw
Kirk Liemohn
I'm glad you were able to build on what I started and thanks for sharing your updates!
Chrissy LeMaire
Thank you! This is the first solution I found that worked, been looking all day.
Kirk Liemohn
Glad it helped!
Declan Turner
Nearly 3 years old but still helpful! Thanks for sharing Kirk.
Out of curiosity, how did you discover the need to concatenate the user id with the identity claim?
Kirk Liemohn
I'm glad this was helpful, Declan. I don't recall, but I suspect that I figured that part out with a little trial and error along with just some deduction based on what I was seeing in the data. Maybe I used Fiddler too :-).