ms crm js调用webservice 带参数的调用
function RequestByPost() { var str_new_lxfs="new_lxfs";//要取的实体字段
var name="new_name" ;//要取的实体字段
var id=Xrm.Page.data.entity.getId();//实体的ID
//webservice地址
var URL = "http://crm:8090/OpportunityWebService.asmx";
var attributes = Xrm.Page.data.entity.attributes.get()//获取实体属性
要调用的webservice的方法
var weburl="http://tempuri.org/InLists2";//
for (var i in attributes) { var attribute = attributes[i];//获取属性
var value = attribute.getValue();//获取值
if (attribute.getName() == str_new_lxfs )
{if (value != null){str_new_lxfs = value ;}else{str_new_lxfs =0;}}
if (attribute.getName() == name )
{if (value != null){name= value ;}else{str_new_lxfs =0;}}
}
//拼接webservice的xml
var data;
data = '<?xml version="1.0" encoding="utf-8"?>';
data = data + '<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/">';
data = data + '<soap:Body>';
data = data + '<InLists2 xmlns="http://tempuri.org/">';
data = data + '<HEADID>' + name+ '</HEADID>';
data = data + '<userID>' + str_new_lxfs+ '</userID>';
data = data + '</InLists2>';
data = data + '</soap:Body>';
data = data + '</soap:Envelope>';
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.Open("POST", URL, false);
xmlhttp.SetRequestHeader("Content-Type", "text/xml; charset=gb2312");
xmlhttp.SetRequestHeader("SOAPAction",weburl);
xmlhttp.Send(data);
document.write(xmlhttp.responseText); }