开发学院网页设计JavaScript 用javascript调用WebService,RetrieveDynamicEnti... 阅读

用javascript调用WebService,RetrieveDynamicEntity的方式取出EntityProperty的Value

 2010-09-14 13:42:39 来源:WEB开发网   
核心提示:function getDynamicEnitity(entityName, entityId,attributeName){ var xml = "" + "<?xml version=\"1.0\" encoding=\"utf-8\"?&

 

function getDynamicEnitity(entityName, entityId,attributeName)
{
    var xml = "" +
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" + GenerateAuthenticationHeader()+"  <soap:Body>" +
"    <Execute xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
"      <Request xsi:type=\"RetrieveRequest\" ReturnDynamicEntities=\"true\">" +
"        <Target xsi:type=\"TargetRetrieveDynamic\">" +
"          <EntityName>"+entityName+"</EntityName>" +
"          <EntityId>"+entityId+"</EntityId>" +
"        </Target>" +
"        <ColumnSet xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:ColumnSet\">" +
"          <q1:Attributes>" +
"            <q1:Attribute>"+attributeName+"</q1:Attribute>" +
"          </q1:Attributes>" +
"        </ColumnSet>" +

"      </Request>" +
"    </Execute>" +
"  </soap:Body>" +
"</soap:Envelope>" +
"";

var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");

xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Execute");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);

var resultXml = xmlHttpRequest.responseXML;
return resultXml;
}

function getEntityPropertyValue(entityName, entityId,attributeName)
{

var resultXml=getDynamicEnitity("quote",entityId,attributeName);
// Create an XML object to parse the results.
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.loadXML(resultXml.xml);

var ret=xmlDoc.selectSingleNode("//Property[@Name='"+attributeName+"']");

//ret.text enough for return xml;
//in other case this may not enough be careful for this.
return ret.text;


}

Tags:javascript 调用 WebService

编辑录入:爽爽 [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
更多精彩
    赞助商链接

    热点阅读
      焦点图片
        最新推荐
          精彩阅读