问题描述
以当事件被激发的时候,代码将会执行为市场活动添加一个产品(市场活动和产品的Guid必须合法)。为例
解决方案
解决方案二:
该示例演示了如何在客户端使用CrmService.Execute方法来为市场活动添加一个产品。如何测试:1:将下面的代码粘贴到“事件详细信息属性”对话框的客户端事件中。2:启用事件并保存,然后通过“预览”选择“创建表单”来验证。代码如下:[JScript]//Preparevariablestoaddanewproducttoacampaign.varCampaignId="771ed82b-6b27-dd11-b452-0003ff9ee217";varEntityId="3F26C82A-A2E1-DC11-A277-001AA0B84538";varEntityName="product";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>"+"<Executexmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"+"<Requestxsi:type='AddItemCampaignRequest'>"+"<CampaignId>"+CampaignId+"</CampaignId>"+"<EntityId>"+EntityId+"</EntityId>"+"<EntityName>"+EntityName+"</EntityName>"+"</Request>"+"</Execute>"+"</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/Execute");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);}//Displayaconfirmationmessageandopenthecampaignrecord.else{alert("Productwithid="+EntityId+"successfullyaddedtoCampaignwithid="+CampaignId+".");window.open("/ma/camps/edit.aspx?id={"+CampaignId+"}");}AsuccessfulresponseincludesXMLthatreturnsaCampaignItemId.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><ExecuteResponsexmlns="http://schemas.microsoft.com/crm/2007/WebServices"><Responsexsi:type="AddItemCampaignResponse"><CampaignItemId>566b89a3-2e7c-43e5-b36f-26be2230f588</CampaignItemId></Response></ExecuteResponse></soap:Body></soap:Envelope>
解决方案三:
获取可用分