JavaScript 调用sharepoint内置webservice(UpdateListItems和GetListItem())
///////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';}
}
}
}