JavaScript 调用sharepoint内置webservice(UpdateListItems和GetListItem())
2011-05-27 10:47
411 查看
///////UpdateListItems
function UpdateListItem()
{
var listName="End User Computing List";
var a = new ActiveXObject("Microsoft.XMLHTTP");
if(a == null) return 'error';
var ID=GetQueryString('ID');
var ddlEvaluation = document.getElementById('ctl00_m_g_959a3f9b_4c02_4c3a_b885_dae28c14a9a8_ff15_1_ctl00_DropDownChoice');
var ddl1 = document.getElementById('ctl00_m_g_959a3f9b_4c02_4c3a_b885_dae28c14a9a8_ff17_1_ctl00_DropDownChoice');
var ddl2 = document.getElementById('ctl00_m_g_959a3f9b_4c02_4c3a_b885_dae28c14a9a8_ff18_1_ctl00_DropDownChoice');
var ddl3 = document.getElementById('ctl00_m_g_959a3f9b_4c02_4c3a_b885_dae28c14a9a8_ff19_1_ctl00_DropDownChoice');
var ddl4 = document.getElementById('ctl00_m_g_959a3f9b_4c02_4c3a_b885_dae28c14a9a8_ff20_1_ctl00_DropDownChoice');
var ddl5 = document.getElementById('ctl00_m_g_959a3f9b_4c02_4c3a_b885_dae28c14a9a8_ff21_1_ctl00_DropDownChoice');
var ddl6 = document.getElementById('ctl00_m_g_959a3f9b_4c02_4c3a_b885_dae28c14a9a8_ff22_1_ctl00_DropDownChoice');
var ddlTechType = document.getElementById('ctl00_m_g_959a3f9b_4c02_4c3a_b885_dae28c14a9a8_ff16_1_ctl00_DropDownChoice');
var txtTechType = document.getElementById('ctl00_m_g_959a3f9b_4c02_4c3a_b885_dae28c14a9a8_ff23_1_ctl00_ctl00_TextField');
a.Open("POST","http://cntsnapp102.zone1.scb.net:2020/_vti_bin/lists.asmx", false);
a.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
a.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");
var d = '<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><Batch OnError="Continue" ListVersion="1">'
+ '<Method ID="1" Cmd="Update">'
+ '<Field Name="ID">' + ID+ '</Field>'
+ '<Field Name="Criticality_x0020_Evaluation">' + ddlEvaluation.value+ '</Field>'
+ '<Field Name="Biz_x0020_Use">' + ddl1.value+ '</Field>'
+ '<Field Name="Biz_x0020_Use2">' + ddl2.value+ '</Field>'
+ '<Field Name="Biz_x0020_Use3">' + ddl3.value+ '</Field>'
+ '<Field Name="Biz_x0020_Use4">' + ddl4.value+ '</Field>'
+ '<Field Name="Biz_x0020_Use5">' + ddl5.value+ '</Field>'
+ '<Field Name="Biz_x0020_Use6">' + ddl6.value+ '</Field>'
+ '<Field Name="Tech_x0020_Type">' + ddlTechType.value+ '</Field>'
+ '<Field Name="Tech_x0020_Type_x0020_Text">' + txtTechType.value+ '</Field>'
+ '</Method>'
+ '</Batch></updates>'
+ '</UpdateListItems>'
+ '</soap:Body>'
+ '</soap:Envelope>';
a.Send(d);
}
//////GetListItems:
function GetListItem()
{
var listName="End User Computing List";
var a = new ActiveXObject("Microsoft.XMLHTTP");
if(a == null) return 'error';
var id=GetQueryString('ID');
var query = '<Query><Where><Eq><FieldRef Name="ID"/><Value Type="Counter">'+id+ '</Value></Eq></Where></Query>';
var view = '<ViewFields><FieldRef Name="Low_x0020_Risk"/><FieldRef Name="Business_x0020_Case_x0020_input"/><FieldRef Name="Procedure_x0020_reading"/><FieldRef Name="Risk_x0020_assessment"/><FieldRef Name="Documentation"/><FieldRef Name="Sign_x002d_off"/><FieldRef Name="Closure"/></ViewFields>';
a.Open("POST","http://cnt5445.zone1.scb.net:2000000/_vti_bin/lists.asmx", false);
a.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
a.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/GetListItems");
var d = '<?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>'
+ '<GetListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">'
+ '<listName>' + listName + '</listName>'
+ '<query>'+query+'</query>'
+ '<viewFields>'+view+'</viewFields>'
+ '<rowLimit>1</rowLimit>'
+ '</GetListItems>'
+ '</soap:Body>'
+ '</soap:Envelope>';
a.Send(d);
if(a.status==200)
{
var rows=a.responseXML.getElementsByTagName('z:row');
if(rows.length == 1)
{
lowRisk=rows[0].getAttribute('ows_Low_x0020_Risk');
process1=rows[0].getAttribute('ows_Business_x0020_Case_x0020_input');
process2=rows[0].getAttribute('ows_Procedure_x0020_reading');
process3=rows[0].getAttribute('ows_Risk_x0020_assessment');
process4=rows[0].getAttribute('ows_Documentation');
process5=rows[0].getAttribute('ows_Sign_x002d_off');
process6=rows[0].getAttribute('ows_Closure');
//alert('title:' + lowRisk);
var href4=document.getElementById('href4');
var href5=document.getElementById('href5');
var href6=document.getElementById('href6');
if(lowRisk=='1')
{
href5.href='EditControlsLR.aspx?ID='+id;
href4.href='EditRiskAssessmentVender.aspx?ID='+id;
href6.href='EditDocumentationManagement.aspx?ID='+id;
}
if(lowRisk=='0')
{
href5.href='EditControlsNLR.aspx?ID='+id;
href4.href='EditRiskAssessmentVender.aspx?ID='+id;
href6.href='EditDocumentationManagement.aspx?ID='+id;
}
var img1=document.getElementById('img1');
if(process1=='1'){img1.src='http://images.cnblogs.com/green.png';}
else{img1.src='http://images.cnblogs.com/red.png';}
var img2=document.getElementById('img2');
if(process2=='1'){img2.src='http://images.cnblogs.com/green.png';}
else{img2.src='http://images.cnblogs.com/red.png';}
var img3=document.getElementById('img3');
if(process3=='1'){img3.src='http://images.cnblogs.com/green.png';}
else{img3.src='http://images.cnblogs.com/red.png';}
var img4=document.getElementById('img4');
if(process4=='1'){img4.src='http://images.cnblogs.com/green.png';}
else{img4.src='http://images.cnblogs.com/red.png';}
var img5=document.getElementById('img5');
if(process5=='1'){img5.src='http://images.cnblogs.com/green.png';}
else{img5.src='http://images.cnblogs.com/red.png';}
var img6=document.getElementById('img6');
if(process6=='1'){img6.src='http://images.cnblogs.com/green.png';}
else{img6.src='http://images.cnblogs.com/red.png';}
}
}
}
function UpdateListItem()
{
var listName="End User Computing List";
var a = new ActiveXObject("Microsoft.XMLHTTP");
if(a == null) return 'error';
var ID=GetQueryString('ID');
var ddlEvaluation = document.getElementById('ctl00_m_g_959a3f9b_4c02_4c3a_b885_dae28c14a9a8_ff15_1_ctl00_DropDownChoice');
var ddl1 = document.getElementById('ctl00_m_g_959a3f9b_4c02_4c3a_b885_dae28c14a9a8_ff17_1_ctl00_DropDownChoice');
var ddl2 = document.getElementById('ctl00_m_g_959a3f9b_4c02_4c3a_b885_dae28c14a9a8_ff18_1_ctl00_DropDownChoice');
var ddl3 = document.getElementById('ctl00_m_g_959a3f9b_4c02_4c3a_b885_dae28c14a9a8_ff19_1_ctl00_DropDownChoice');
var ddl4 = document.getElementById('ctl00_m_g_959a3f9b_4c02_4c3a_b885_dae28c14a9a8_ff20_1_ctl00_DropDownChoice');
var ddl5 = document.getElementById('ctl00_m_g_959a3f9b_4c02_4c3a_b885_dae28c14a9a8_ff21_1_ctl00_DropDownChoice');
var ddl6 = document.getElementById('ctl00_m_g_959a3f9b_4c02_4c3a_b885_dae28c14a9a8_ff22_1_ctl00_DropDownChoice');
var ddlTechType = document.getElementById('ctl00_m_g_959a3f9b_4c02_4c3a_b885_dae28c14a9a8_ff16_1_ctl00_DropDownChoice');
var txtTechType = document.getElementById('ctl00_m_g_959a3f9b_4c02_4c3a_b885_dae28c14a9a8_ff23_1_ctl00_ctl00_TextField');
a.Open("POST","http://cntsnapp102.zone1.scb.net:2020/_vti_bin/lists.asmx", false);
a.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
a.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/UpdateListItems");
var d = '<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><Batch OnError="Continue" ListVersion="1">'
+ '<Method ID="1" Cmd="Update">'
+ '<Field Name="ID">' + ID+ '</Field>'
+ '<Field Name="Criticality_x0020_Evaluation">' + ddlEvaluation.value+ '</Field>'
+ '<Field Name="Biz_x0020_Use">' + ddl1.value+ '</Field>'
+ '<Field Name="Biz_x0020_Use2">' + ddl2.value+ '</Field>'
+ '<Field Name="Biz_x0020_Use3">' + ddl3.value+ '</Field>'
+ '<Field Name="Biz_x0020_Use4">' + ddl4.value+ '</Field>'
+ '<Field Name="Biz_x0020_Use5">' + ddl5.value+ '</Field>'
+ '<Field Name="Biz_x0020_Use6">' + ddl6.value+ '</Field>'
+ '<Field Name="Tech_x0020_Type">' + ddlTechType.value+ '</Field>'
+ '<Field Name="Tech_x0020_Type_x0020_Text">' + txtTechType.value+ '</Field>'
+ '</Method>'
+ '</Batch></updates>'
+ '</UpdateListItems>'
+ '</soap:Body>'
+ '</soap:Envelope>';
a.Send(d);
}
//////GetListItems:
function GetListItem()
{
var listName="End User Computing List";
var a = new ActiveXObject("Microsoft.XMLHTTP");
if(a == null) return 'error';
var id=GetQueryString('ID');
var query = '<Query><Where><Eq><FieldRef Name="ID"/><Value Type="Counter">'+id+ '</Value></Eq></Where></Query>';
var view = '<ViewFields><FieldRef Name="Low_x0020_Risk"/><FieldRef Name="Business_x0020_Case_x0020_input"/><FieldRef Name="Procedure_x0020_reading"/><FieldRef Name="Risk_x0020_assessment"/><FieldRef Name="Documentation"/><FieldRef Name="Sign_x002d_off"/><FieldRef Name="Closure"/></ViewFields>';
a.Open("POST","http://cnt5445.zone1.scb.net:2000000/_vti_bin/lists.asmx", false);
a.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
a.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/GetListItems");
var d = '<?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>'
+ '<GetListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">'
+ '<listName>' + listName + '</listName>'
+ '<query>'+query+'</query>'
+ '<viewFields>'+view+'</viewFields>'
+ '<rowLimit>1</rowLimit>'
+ '</GetListItems>'
+ '</soap:Body>'
+ '</soap:Envelope>';
a.Send(d);
if(a.status==200)
{
var rows=a.responseXML.getElementsByTagName('z:row');
if(rows.length == 1)
{
lowRisk=rows[0].getAttribute('ows_Low_x0020_Risk');
process1=rows[0].getAttribute('ows_Business_x0020_Case_x0020_input');
process2=rows[0].getAttribute('ows_Procedure_x0020_reading');
process3=rows[0].getAttribute('ows_Risk_x0020_assessment');
process4=rows[0].getAttribute('ows_Documentation');
process5=rows[0].getAttribute('ows_Sign_x002d_off');
process6=rows[0].getAttribute('ows_Closure');
//alert('title:' + lowRisk);
var href4=document.getElementById('href4');
var href5=document.getElementById('href5');
var href6=document.getElementById('href6');
if(lowRisk=='1')
{
href5.href='EditControlsLR.aspx?ID='+id;
href4.href='EditRiskAssessmentVender.aspx?ID='+id;
href6.href='EditDocumentationManagement.aspx?ID='+id;
}
if(lowRisk=='0')
{
href5.href='EditControlsNLR.aspx?ID='+id;
href4.href='EditRiskAssessmentVender.aspx?ID='+id;
href6.href='EditDocumentationManagement.aspx?ID='+id;
}
var img1=document.getElementById('img1');
if(process1=='1'){img1.src='http://images.cnblogs.com/green.png';}
else{img1.src='http://images.cnblogs.com/red.png';}
var img2=document.getElementById('img2');
if(process2=='1'){img2.src='http://images.cnblogs.com/green.png';}
else{img2.src='http://images.cnblogs.com/red.png';}
var img3=document.getElementById('img3');
if(process3=='1'){img3.src='http://images.cnblogs.com/green.png';}
else{img3.src='http://images.cnblogs.com/red.png';}
var img4=document.getElementById('img4');
if(process4=='1'){img4.src='http://images.cnblogs.com/green.png';}
else{img4.src='http://images.cnblogs.com/red.png';}
var img5=document.getElementById('img5');
if(process5=='1'){img5.src='http://images.cnblogs.com/green.png';}
else{img5.src='http://images.cnblogs.com/red.png';}
var img6=document.getElementById('img6');
if(process6=='1'){img6.src='http://images.cnblogs.com/green.png';}
else{img6.src='http://images.cnblogs.com/red.png';}
}
}
}
相关文章推荐
- [导入]使用Sharepoint的Lists Web Service调用UpdateListItems方法"增/删/改"List Items
- SharePoint 2013 中使用 JavaScript Like 和Unlike list item/page/document
- 如何通过js跨域调用ASP.NET Web API (请问如何实现在javascript中通过http get的方式跨域调用ASP.NET Web API?)
- 在atlas里面的UpdatePanel控件中调用javascript,以及updatePanel的一些原理
- Effective JavaScript Item 63 注意异步调用中可能会被忽略的异常
- How to: Update List Items
- 修改ListItem时出现Error: Invalid data has been used to update the list item. The field you are trying to update may be read only.
- listfragment onlistitemclick 没有响应 没有调用
- Director中调用AS3.0对象-getVariable 附源码 - 20151228update
- Moss2007 UpdateListItems方法报错 ErrorCode 0x81020014
- cs_Content_CreateUpdateDelete///cs_Content_GetList///cs_Content_Load
- 淘宝api升级,无法采集淘宝的数据,taobao.item.get 和taobao.taobaoke.items.get都不能用
- jquery里面调用getjson方法,将list类型转换为json格式数据,在页面迭代显示
- JavaScript子类用Object.getPrototypeOf去调用父类方法
- JavaScript子类用Object.getPrototypeOf去调用父类方法解析
- get random items form list
- Effective JavaScript Item 63 注意异步调用中可能会被忽略的异常
- Effective JavaScript Item 30 理解prototype, getPrototypeOf和__proto__的不同
- Update list item using Linq to SharePoint
- SPList.GetItemById(int)和SPList.Items.GetItemById(int)的区别