0

我正在尝试使用 Lists Web 服务中的“UpdateListItems”方法更新 SharePoint 列表项。CAML 查询:

"<Method ID='1' Cmd='Update'>" +
           "<Field Name='ID'>" + itemID + "</Field>" +
           "<Field Name='Status'>" + itemStatus + "</Field></Method>"

itemID、itemStatus 并作为参数从 UI 传递。这给出了以下错误

<Result ID="1,Update">
<ErrorCode>0x80070005</ErrorCode>
<ErrorText>The operation failed because an unexpected error occurred. (Result Code: 0x80070005)
</ErrorText>
</Result>

任何人都可以帮助。另一个问题是更新方法仅基于 ID 工作,或者是否也有可能通过 Title。

谢谢

4

2 回答 2

1

您目前可能不需要,但这可能对其面临相同问题的其他人有所帮助。

有时,此错误的原因是 SOAP 操作中的标头。您需要设置以下内容才能进行更新:

beforeSend: function(xhr) { xhr.setRequestHeader("SOAPAction", " http://schemas.microsoft.com/sharepoint/soap/UpdateListItems ");

我创建了以下函数来在 Sharepoint 列表中发送更新:

function sendupdates(location,listName,command,fieldnames,fieldvalues){
      var updatesvar;
      for(x=0;x<fieldnames.length;x++){
      updatesvar =   updatesvar + '<Field Name="'+fieldnames[x]+'">'+fieldvalues[x]+'</Field>'
         }

      var batchvar = '<Batch OnError="Continue" ListVersion="0"><Method ID="1" Cmd="'+command+'">'+updatesvar+'</Method></Batch>';

      var soapEnv =
                  '<?xml version="1.0" encoding="utf-8"?>'+
                  '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'+
                  '<soap:Body>'+
                  '<UpdateListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">'+
                  '<listName>'+listName+'</listName>'+
                  '<updates>'+batchvar+'</updates>'+
                  '</UpdateListItems>'+
                  '</soap:Body>'+
                  '</soap:Envelope>';

           $.ajax({
                  url: location+"/_vti_bin/Lists.asmx",
                  beforeSend: function(xhr) { xhr.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");},
                  type: "POST",
                  dataType: "xml",
                  data: soapEnv,
                  complete: complete,   
                  contentType: "text/xml; charset=\"utf-8\""
              });

  }
于 2015-06-04T14:03:37.450 回答
0

尝试使用以下 CAML 工具之一:http: //msdn.microsoft.com/en-us/library/ff648040.aspx

于 2011-08-09T00:29:51.917 回答