0

まず、私が使用しているもの:

  • SharePoint 2007
  • JavaScript
  • CAML クエリ
  • 標準 Web サービス (_vti_bin/lists.asmx)

いくつかの条件に応じて、リストから 1 つまたは複数の項目を選択しています。アイテムを取得し、別の条件を実行します。条件が満たされた場合、アイテムをバンプしたい、つまり、「変更済み」列を現在の日付/時刻に変更しますが、値は変更しないでください。

これは可能ですか?もしそうなら、どうすればこれを行うことができますか?

前もって感謝します!

4

1 に答える 1

1

私はすでに同じことをしなければなりませんでした。コードを見つけることができませんが、そのとき私を助けてくれた投稿を見つけました。これはC#で書かれていますが、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

于 2013-02-05T13:50:59.650 に答える