使用 SharePoint 列表项更新列表项

发布于 2024-11-28 13:06:27 字数 648 浏览 2 评论 0原文

我正在尝试使用列表 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。

谢谢

I am trying to update SharePoint List Item using "UpdateListItems" method in Lists Web service.
CAML Query:

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

itemID,itemStatus and passed from UI as parameters.
This gives following error

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

Can any one help.
One more question is the update method works only based on ID or is there any possibility of passing Title also.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

像极了他 2024-12-05 13:06:27

您现在可能不需要,但这可能对面临同样问题的其他人有帮助。

有时,此错误的原因是 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\""
              });

  }

You might not need at this moment, however this might be helpful for someone else facing the same issue.

Sometimes the reason for this error is the headers in the SOAP action. You need to set the following in order to make updates.:

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

I've created the following function to send updates at Sharepoint Lists:

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\""
              });

  }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文