I manage a request list in SharePoint 2013, and I need to import some requests from another list. However, I want to keep the original request date rather than have SharePoint assign the current date/time that I upload the requests, so I want to change the default "Created" date field. I got this to work for a date column that I added:
var duedate = new Date(2015,01,11).toISOString();
$().SPServices({
operation: "UpdateListItems",
async: false,
listName: "Requests",
ID: 5,
valuepairs: [["DueDate", duedate]],
completefunc: function (xData, Status) {
}
});
It doesn't work for the "Created" field though - I think because it's read only. I need a way to make the "Created" field editable so I can change the date. I have a lot of code already written that references this column so I would rather not make a new column that defaults to "Created" unless changed.
Bonus: my next task will be to change the default "Author" field so hopefully the solution can also make that field editable.
The short answer: you cant. System fields such as Created
, Modified
, Created By
, Modified By
are not supported to be updated via SharePoint Web Services UpdateListItems
operation.
Note:
Created By (Author)
andModified By(Editor)
fields can be updated in this manner only for non-library SharePoint lists
But there is a workaround. Basically the reason why those field could not be updated is because they are declared as ReadOnly. So, after modifying list schema to make system fields available for modification (set ReadOnly
attribute to false) as shown below for Created
field:
var updateSystemFields = "<Fields>" +
"<Method ID='1'>" +
"<Field ID='{8c06beca-0777-48f7-91c7-6da68bc07b69}' ColName='tp_Created' RowOrdinal='0' ReadOnly='FALSE' Type='DateTime' Name='Created' DisplayName='Created' StorageTZ='TRUE' SourceID='http://schemas.microsoft.com/sharepoint/v3' StaticName='Created' FromBaseType='TRUE' Version='4' ShowInNewForm='FALSE' ShowInEditForm='FALSE' />" +
"</Method>" +
"</Fields>";
$().SPServices({
operation: "UpdateList",
listName: "Requests",
listProperties:"",
updateFields: updateSystemFields,
newFields: "",
deleteFields: "",
listVersion: "",
async: false,
completefunc: function (xData, Status){
console.log('List schema has been modified');
}
});
list item Created
field value could be updated using UpdateListItems
operation:
var dueDateVal = new Date('2016-01-01 6:00:00').toISOString();
$().SPServices({
operation: "UpdateListItems",
async: false,
listName: "Requests",
ID: 1,
valuepairs: [["Created", dueDateVal]],
completefunc: function (xData, Status) {
console.log('List item has been updated');
}
});