首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >"Bump“a SharePoint ListItem而不更改值

"Bump“a SharePoint ListItem而不更改值
EN

Stack Overflow用户
提问于 2013-02-04 16:47:15
回答 1查看 612关注 0票数 0

首先,我使用的是:

  • SharePoint 2007
  • JavaScript
  • CAML查询
  • 标准webservice (_vti_bin/lists.asmx)

根据某些条件,我从列表中选择一个或多个项目。我得到这些物品,并对它们执行另一个条件。如果满足了条件,我想增加项目,这意味着:将“修改”列更改为当前日期/时间,但不应更改任何值。

这个是可能的吗?如果是的话,如何才能做到呢?

提前感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-05 13:50:59

我已经不得不做同样的事了。虽然我找不到代码,但我找到了那个帮助我的帖子。它是用C#编写的,但很容易适应javascript:

代码语言:javascript
复制
public void Test()
        {
            string webUrl = "http://myserver";
            string listName = "docs";
            Lists.ListsSoapClient listsClient = this.GetListsClient(webUrl);

            // 1st a call to Lists.GetList - we need the list's version - it is returned in the Version attribute
            XElement listData = XElement.Parse(listsClient.GetList(listName).OuterXml);
            string listID = listData.Attribute("ID").Value;
            string version = listData.Attribute("Version").Value;
            // in the updateFields parameter of Lists.UpdateList the full schema of the fields should be provided
            string updateFields = @"<Fields>
   <Method ID='1'>
      <Field ID='{28cf69c5-fa48-462a-b5cd-27b6f9d2bd5f}' ColName='tp_Modified' RowOrdinal='0' ReadOnly='FALSE' Type='DateTime' Name='Modified' DisplayName='Modified' StorageTZ='TRUE' SourceID='http://schemas.microsoft.com/sharepoint/v3' StaticName='Modified' FromBaseType='TRUE' Version='4' ShowInNewForm='FALSE' ShowInEditForm='FALSE' />
   </Method>
   <Method ID='2'>
      <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>";
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(updateFields);
            // Lists.UpdateList: set fields to not read-only
            XElement result = XElement.Parse(listsClient.UpdateList(listID, null, null, doc.DocumentElement, null, version).OuterXml);
            // get updated version from the result XML - for the second call of Lists.UpdateList
            version = result.Elements().Where(el => el.Name.LocalName == "ListProperties").First().Attribute("Version").Value;

            // prepare the XML for the list item update
            string updateDates = @"<Batch OnError='Continue'>
  <Method ID='M0' Cmd='Update'>
    <Field Name='ID'>1</Field>
    <Field Name='FileRef'>/docs/zt.txt</Field>
    <Field Name='Modified'>2010-04-04T22:17:00Z</Field>
    <Field Name='Created'>2010-01-01T00:05:00Z</Field>
  </Method>
</Batch>";

            doc.LoadXml(updateDates);
            // Lists.UpdateListItems: update Created & Modified
            result = XElement.Parse(listsClient.UpdateListItems(listID, doc.DocumentElement).OuterXml);

            // revert the fields' schema
            updateFields = updateFields.Replace("ReadOnly='FALSE'", "ReadOnly='TRUE'");
            doc.LoadXml(updateFields);
            // Lists.UpdateList: set fields back to read-only
            result = XElement.Parse(listsClient.UpdateList(listID, null, null, doc.DocumentElement, null, version).OuterXml);
        }

基本上,在尝试更新字段之前,我们必须将字段的只读属性设置为false,并且在更新之后,将该属性设置为true。

来源:http://stefan-stanev-sharepoint-blog.blogspot.com.br/2010/04/updating-read-only-fields-with-lists.html

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14691345

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档