问题描述
以当事件被激发的时候,代码将会执行获取address1_city为“Sammamish”的全部联系人的ID和全名。为例
解决方案
解决方案二:
该示例演示了如何在客户端使用CrmService.RetrieveMultiple方法来获取多个联系人的信息。如何测试:1:将下面的代码粘贴到“事件详细信息属性”对话框的客户端事件中。2:启用事件并保存,然后通过“预览”选择“创建表单”来验证。代码如下:[JScript]//Preparevariablestoretrievethecontacts.varsearchCity="Sammamish";varauthenticationHeader=GenerateAuthenticationHeader();//PreparetheSOAPmessage.varxml="<?xmlversion='1.0'encoding='utf-8'?>"+"<soap:Envelopexmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'"+"xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"+"xmlns:xsd='http://www.w3.org/2001/XMLSchema'>"+authenticationHeader+"<soap:Body>"+"<RetrieveMultiplexmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"+"<queryxmlns:q1='http://schemas.microsoft.com/crm/2006/Query'"+"xsi:type='q1:QueryExpression'>"+"<q1:EntityName>contact</q1:EntityName>"+"<q1:ColumnSetxsi:type='q1:ColumnSet'>"+"<q1:Attributes>"+"<q1:Attribute>fullname</q1:Attribute>"+"<q1:Attribute>contactid</q1:Attribute>"+"</q1:Attributes>"+"</q1:ColumnSet>"+"<q1:Distinct>false</q1:Distinct>"+"<q1:Criteria>"+"<q1:FilterOperator>And</q1:FilterOperator>"+"<q1:Conditions>"+"<q1:Condition>"+"<q1:AttributeName>address1_city</q1:AttributeName>"+"<q1:Operator>Like</q1:Operator>"+"<q1:Values>"+"<q1:Valuexsi:type='xsd:string'>"+searchCity+"</q1:Value>"+"</q1:Values>"+"</q1:Condition>"+"</q1:Conditions>"+"</q1:Criteria>"+"</query>"+"</RetrieveMultiple>"+"</soap:Body>"+"</soap:Envelope>";//PreparethexmlHttpObjectandsendtherequest.varxHReq=newActiveXObject("Msxml2.XMLHTTP");xHReq.Open("POST","/mscrmservices/2007/CrmService.asmx",false);xHReq.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");xHReq.setRequestHeader("Content-Type","text/xml;charset=utf-8");xHReq.setRequestHeader("Content-Length",xml.length);xHReq.send(xml);//Capturetheresult.varresultXml=xHReq.responseXML;//Checkforerrors.varerrorCount=resultXml.selectNodes('//error').length;if(errorCount!=0){varmsg=resultXml.selectSingleNode('//description').nodeTypedValue;alert(msg);}//Parseanddisplaytheresults.else{varresults=resultXml.getElementsByTagName('BusinessEntity');varmsg="";if(results.length==0){msg="Nocontactswerefoundin"+searchCity+".";alert(msg);return;}else{msg="Contactsfoundin"+searchCity+":r";msg+="ContactIdttttContactFullNamer";msg+="--------------------------------------------------------------------------------r";for(i=0;i<results.length;i++){varidValue=results[i].selectSingleNode('./q1:contactid').nodeTypedValue;varname=results[i].selectSingleNode('./q1:fullname').nodeTypedValue;msg+=idValue+"t"+name+"r";}alert(msg);}}Thefollowingisanexampleofasuccessfulresponse:<?xmlversion="1.0"encoding="utf-8"?><soap:Envelopexmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><RetrieveMultipleResponsexmlns="http://schemas.microsoft.com/crm/2007/WebServices"><RetrieveMultipleResultEntityName="contact"MoreRecords="0"PagingCookie=""><BusinessEntitiesxmlns="http://schemas.microsoft.com/crm/2006/WebServices"><BusinessEntityxmlns:q1="http://schemas.microsoft.com/crm/2007/WebServices"xsi:type="q1:contact"><q1:fullname>FirstNameLastName</q1:fullname><q1:contactid>{56914948-991C-DD11-AD3A-0003FF9EE217}</q1:contactid></BusinessEntity><BusinessEntityxmlns:q1="http://schemas.microsoft.com/crm/2007/WebServices"xsi:type="q1:contact"><q1:fullname>FirstNameLastName</q1:fullname><q1:contactid>{4696F8CB-9A1C-DD11-AD3A-0003FF9EE217}</q1:contactid></BusinessEntity><BusinessEntityxmlns:q1="http://schemas.microsoft.com/crm/2007/WebServices"xsi:type="q1:contact"><q1:fullname>FirstNameLastName</q1:fullname><q1:contactid>{368C8B1B-851C-DD11-AD3A-0003FF9EE217}</q1:contactid></BusinessEntity></BusinessEntities></RetrieveMultipleResult></RetrieveMultipleResponse></soap:Body></soap:Envelope>
解决方案三:
SDKhasmanycodeexamples.