0

I am using managed client object model for creating list item, I want to update the Author, Created and Editor fields from code. I have tried lot of things like:

var listItem = list.AddItem(listItemCreationInformation); 
listItem["Title"] = "Migrated Date"; 
listItem["Modified"] = DateTime.Now.AddDays(-10); 

//Date Value listItem["Created"] = DateTime.Now.AddDays(-10); 
listItem["Author"] = GetUser(clientContext, "Domain\\userId"); 
listItem["Editor"] = GetUser(clientContext, "Domain\\userId"); 
listItem["CORID"] = folderPath; 
listItem.Update(); 

clientContext.ExecuteQuery();
  • Please share what you have tried – Robert Lindgren May 21 '14 at 13:44
  • Hi Robert,I have posted the code.. – Sreejith May 21 '14 at 13:49
  • It seems like the user executing the code needs Full Control permission on the list to update the author and editor fields. – user47492 Oct 2 '15 at 11:30
1

I'm 99% sure that you need to retrieve the item back and then update those fields. try this:

var newListItem = list.AddItem(listItemCreationInformation); 
var listItem = list.getItemById(newListItem.Id);

listItem["Title"] = "Migrated Date"; 
listItem["Modified"] = DateTime.Now.AddDays(-10); 

//Date Value listItem["Created"] = DateTime.Now.AddDays(-10); 
listItem["Author"] = GetUser(clientContext, "Domain\\userId"); 
listItem["Editor"] = GetUser(clientContext, "Domain\\userId"); 
listItem["CORID"] = folderPath; 
listItem.Update(); 

clientContext.ExecuteQuery();

Note the 2nd line that fetches the newly created item.

  • Hi Rob,thanks for the help,still not able to update – Sreejith May 22 '14 at 6:09
0

As these are read only fields, you might not be able to update it as per my understanding.

However you can try following code whether it works or not as its trying to change the readonly property of the list:

FieldUserValue fldUser = new FieldUserValue();
fldUser.LookupId = oUser.Id;
clientContext.Load(fldUser);
clientContext.ExecuteQuery();
oListItem["Author"] = fldUser;
oListItem["Editor"] = fldUser;

If the above code doesn't work means, the Author and Editor field maybe a ReadOnly Field, So we have to remove the readOnly mode from that field.

list.Fields.GetByInternalNameOrTitle("Author").ReadOnlyField = false;
  • Hi Robert,Thanks for the Suggestion, i tried your code too...still im unable to update. – Sreejith May 21 '14 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.