最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Change Created Date in SharePoint 2013 - Stack Overflow

programmeradmin3浏览0评论

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]],
    pletefunc: 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.

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]],
    pletefunc: 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.

Share asked Sep 19, 2015 at 0:20 greenbellpeppergreenbellpepper 4222 gold badges8 silver badges14 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 4

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) and Modified 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./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,
  pletefunc: 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]],
    pletefunc: function (xData, Status) {
         console.log('List item has been updated');
    }
});
发布评论

评论列表(0)

  1. 暂无评论