20.10.2009, 19:05 | #1 |
Участник
|
CRM Programmer: MS CRM Fetch and Retrieve from javascript
Источник: http://crmpro.blogspot.com/2009/10/m...ieve-from.html
============== This code snippet was writing exactly like recommended in MSCRM SDK 4.09. I was put it in OnLoad() event of my account form, and in the lookup field(at my example - new_postalcodeid) at OnChange() event I was calling my function. There is two function that are doing the same work but with different methods. var authenticationHeader = GenerateAuthenticationHeader(); crmForm.all.address1_city.ForceSubmit = true; window.GetRegionByIndex_Retrieve = function() { if (crmForm.all.new_postalcodeid.DataValue == null) { crmForm.all.address1_city.Disabled = false; crmForm.all.address1_city.DataValue = ""; return; } var lookupItem = new Array; lookupItem = crmForm.all.new_postalcodeid.DataValue; if(lookupItem[0] != null) { // Prepare the SOAP message. var xml = ""+ ""+ authenticationHeader+ ""+ ""+ "new_postalcode"+ ""+lookupItem[0].id+""+ ""+ ""+ "new_regcityarea"+ ""+ ""+ ""+ ""+ ""; // Prepare the xmlHttpObject and send the request. var xHReq = new ActiveXObject("Msxml2.XMLHTTP"); xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false); xHReq.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Retrieve"); xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); xHReq.setRequestHeader("Content-Length", xml.length); xHReq.send(xml); // Capture the result. var resultXml = xHReq.responseXML; // Check for errors. var errorCount = resultXml.selectNodes('//error').length; if (errorCount != 0) { var msg = resultXml.selectSingleNode('//description').nodeTypedValue; alert(msg); } // Display the retrieved value. else { crmForm.all.address1_city.DataValue = resultXml.selectSingleNode("//q1:new_regcityarea").nodeTypedValue; crmForm.all.address1_city.Disabled = true; } } } window.GetRegionByIndex_Fetch = function (){ if (crmForm.all.new_postalcodeid.DataValue == null) { crmForm.all.address1_city.Disabled = false; crmForm.all.address1_city.DataValue = ""; return; } var lookupItem = new Array; lookupItem = crmForm.all.new_postalcodeid.DataValue; if(lookupItem[0] != null) { var xml = "" + "" + authenticationHeader + "" + "" + "" + "<fetch mapping='logical'>" + "<entity name='new_postalcode'>" + "<attribute name='new_postalcodeid'/>"+ "<attribute name='new_regcityarea'/>"+ "<filter type='and'>"+ "<condition attribute='new_postalcodeid' operator='eq' value='"+lookupItem[0].id+"'/>"+ "</filter></entity></fetch>" + "" + "" + " " + ""; var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP"); xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false); xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Fetch"); xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); xmlHttpRequest.setRequestHeader("Content-Length", xml.length); xmlHttpRequest.send(xml); var resultXml = xmlHttpRequest.responseXML; // Check for errors. var errorCount = resultXml.selectNodes('//error').length; if (errorCount != 0) { var msg = resultXml.selectSingleNode('//description').nodeTypedValue; alert(msg); } // Process and display the results. else { // Capture the result and UnEncode it. var resultSet = new String(); resultSet = resultXml.text; resultSet.replace('<',''); var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async = false; xmlDoc.loadXML(resultSet); var results = xmlDoc.getElementsByTagName('result'); for(i=0;i
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору. |
|