简体   繁体   English

使用 SPServices UpdateListItems 在 SharePoint 2013 中设置日期

[英]Use SPServices UpdateListItems to set date in SharePoint 2013

I cannot find a working solution to set a SharePoint 2013 list date using SPServices.我找不到使用 SPServices 设置 SharePoint 2013 列表日期的可行解决方案。 I have done this multiple times for other column types, but I can't figure out the right format for dates.对于其他列类型,我已经多次执行此操作,但我无法找出正确的日期格式。 Here's what I'm doing:这是我在做什么:

var testdate = "2016-01-01 00:00:00";
$().SPServices({
    operation: "UpdateListItems",
    async: false,
    listName: "Requests",
    ID: 4,
    valuepairs: [["Due Date", testdate]],
    completefunc: function (xData, Status) {
    }
});

I have also tried it with these test values, but nothing changes on my site:我也用这些测试值尝试过,但我的网站上没有任何变化:

var testdate = "2016-1-1 0:0:0";
var testdate = "2016-01-01T00:00:00Z";
var testdate = "2016-1-1T0:0:0Z";
var testdate = "2016-01-01T00:00:00";
var testdate = "2016-1-1T0:0:0";

Please let me know if there's another date format I should try, or if you see anything else wrong with this code.请让我知道是否还有其他日期格式我应该尝试,或者如果您发现此代码有任何其他错误。 It works when I point to one of my text fields, so I'm pretty sure it's just the date format that's messing things up.当我指向我的一个文本字段时它会起作用,所以我很确定这只是日期格式把事情搞砸了。

UpdateListItems operation expects date string to be provided in ISO 8601 format , for example: UpdateListItems操作需要以ISO 8601 格式提供日期字符串,例如:

var dueDateVal = new Date('2016-01-01 6:00:00').toISOString();
$().SPServices({
    operation: "UpdateListItems",
    async: false,
    listName: "Requests",
    ID: 1,
    valuepairs: [["DueDate", dueDateVal]],
    completefunc: function (xData, Status) {
         console.log('List items has been updated');
    }
});

In addition, make sure the proper name of Due Date column is specified.此外,请确保指定了Due Date列的正确名称 UpdateListItems operation expects an array of column StaticNames and values have to be specified for valuepairs . UpdateListItems操作需要一个包含StaticNames列的数组,并且必须为valuepairs指定valuepairs

If column named Due Date has been created via UI, then Due_x0020_Date static name will be generated and the operation for setting its value the should be specified like this:如果通过 UI 创建了名为Due Date列,则将生成Due_x0020_Date静态名称,并应如下指定设置其值的操作:

var dueDateVal = new Date('2016-01-01 6:00:00').toISOString();
$().SPServices({
    operation: "UpdateListItems",
    async: false,
    listName: "Requests",
    ID: 1,
    valuepairs: [["Due_x0020_Date", dueDateVal]],
    completefunc: function (xData, Status) {
         console.log('List items has been updated');
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM