使用caml查询更新多个项目 [英] Update multiple items using caml query

查看:77
本文介绍了使用caml查询更新多个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用caml查询将表中已修改列的所有行从共享点页面更新为外部列表.

I need to update all the rows of a modified column in a table from share point page to external list using caml query. 

请咨询.

推荐答案

您可以尝试下面的脚本.

<script  type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

<script type="text/javascript">

function GetItemstoUpdate(){

var soapEnv = "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> \
 <soap:Body> \
 <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
 <listName>Project List</listName> \
<query><Query><Where><Gt><FieldRef Name='ProjectCost'/><Value Type='Number'>1000</Value></Gt></Where></Query></query> \
 <viewFields> \
 <ViewFields> \
 <FieldRef Name='Title' /> \
 <FieldRef Name='Project_x0020_Id' /> \
 <FieldRef Name='ID' /> \
 </ViewFields> \
 </viewFields> \
 <rowLimit>99999</rowLimit> \
 <queryOptions xmlns:SOAPSDK9='http://schemas.microsoft.com/sharepoint/soap/' ><QueryOptions/> \
 </queryOptions> \
 </GetListItems> \
 </soap:Body> \
 </soap:Envelope>";
jQuery.ajax({
 url: "/_vti_bin/lists.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
 complete: CreateBatchWithListItems,
 contentType: "text/xml; charset=\"utf-8\""
 });
}
function CreateBatchWithListItems(xData, status) {

var oldbatch ="";
jQuery(xData.responseXML).find("z\\:row").each(function () {
oldbatch = AddTobatch(oldbatch,


(this).attr("ows_ID"))); }); UpdateItems(oldbatch); } 函数AddTobatch(oldbatch,itemId) { //指定批处理查询 var _batch =<方法ID ='1'Cmd ='Update'><字段名='ID'>" + itemId +</Field><字段名称='状态'>已转移</Field>/方法/""; oldbatch = oldbatch + _batch; 返还旧批次; } 函数UpdateItems(批次){ var soapEnv =<?xml version = \'1.0 \'encoding = \'utf-8 \'?> \ < soap:信封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> \ <更新> \ < Batch OnError ='Continue'>" +批次+</批次"> \ </updates> \ </UpdateListItems> \ </soap:Body> \ </soap:Envelope>"; jQuery.ajax({ 网址:"/_ vti_bin/lists.asmx", beforeSend:function(xhr){xhr.setRequestHeader("SOAPAction","http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");}, 类型:"POST", dataType:"xml", 数据:soapEnv, 完成:updateResult, contentType:"text/xml; charset = \"utf-8 \" }); } 函数updateResult(xData,status){ 警报(更新完成"); } </script>
(this).attr("ows_ID")); }); UpdateItems(oldbatch); } function AddTobatch(oldbatch, itemId) { //Specify the batch query var _batch = "<Method ID='1' Cmd='Update'><Field Name='ID'>" + itemId +"</Field><Field Name='Status'>Transferred</Field></Method>"; oldbatch = oldbatch + _batch; return oldbatch; } function UpdateItems(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>Project List</listName> \ <updates> \ <Batch OnError='Continue'>" + batch + "</Batch> \ </updates> \ </UpdateListItems> \ </soap:Body> \ </soap:Envelope>"; jQuery.ajax({ url: "/_vti_bin/lists.asmx", beforeSend: function(xhr) { xhr.setRequestHeader("SOAPAction","http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");}, type: "POST", dataType: "xml", data: soapEnv, complete: updateResult, contentType: "text/xml; charset=\"utf-8\"" }); } function updateResult(xData, status) { alert("Update Complete"); } </script>

这里是链接以供参考.

最好的问候,

Lee


这篇关于使用caml查询更新多个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆