How to get related records in SOAP based on N: N relationship

We are trying to use SOAP to retrieve related records based on the N: N relationship. Thus, we have 1 GUID for 1 object retrieved from the current form. Then we need all the GUIDs from another object. How to form our SOAP request correctly.

RetrieveContacts = function (EntityName, EntityKeyName, contactGUID) { // Prepare IDs to retrieve the records var authenticationHeader = GenerateAuthenticationHeader(); // Prepare the SOAP message. var xml = ""; xml += "<?xml version='1.0' encoding='utf-8'?>"; xml += "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'"; xml += " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"; xml += " xmlns:xsd='http://www.w3.org/2001/XMLSchema'>"; xml += authenticationHeader; xml += "<soap:Body>"; xml += "<RetrieveMultiple xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"; xml += "<query xmlns:q1='http://schemas.microsoft.com/crm/2006/Query'"; xml += " xsi:type='q1:QueryExpression'>"; xml += "<q1:EntityName>" + EntityName + "</q1:EntityName>"; xml += "<q1:ColumnSet xsi:type='q1:ColumnSet'>"; xml += "<q1:Attributes>"; xml += "<q1:Attribute>" + EntityKeyName + "</q1:Attribute>"; xml += "</q1:Attributes>"; xml += "</q1:ColumnSet>"; xml += "<q1:Distinct>false</q1:Distinct>"; xml += "<q1:Criteria>"; xml += "<q1:Conditions>"; xml += "<q1:Condition>"; xml += "<q1:AttributeName>" + EntityKeyName + "</q1:AttributeName>"; xml += "<q1:Operator>Equal</q1:Operator>"; xml += "<q1:Values>"; xml += "<q1:Value xsi:type='xsd:string'>" + contactGUID + "</q1:Value>"; xml += "</q1:Values>"; xml += "</q1:Condition>"; xml += "</q1:Conditions>"; xml += "</q1:Criteria>"; xml += "</query>"; xml += "</RetrieveMultiple>"; xml += "</soap:Body>"; xml += "</soap:Envelope>"; // 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/RetrieveMultiple"); 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); } // Parse and display the results. else { var results = resultXml.getElementsByTagName('BusinessEntity'); var msg = ""; if (results.length == 0) { msg = "No records to submit."; alert(msg); return; } else { for (i = 0; i < results.length; i++) { var idValue = results[i].selectSingleNode('./q1:' + EntityKeyName).nodeTypedValue; //Now insert the new RSVP record msg += idValue + "\t" + name + "\r"; } alert(msg); } } } 
+4
source share
1 answer

Of course, I use the 2011 service, but here is an example of using SOAP from JavaScript http://blog.customereffective.com/blog/2011/05/execute-fetch-from-javascript-in-crm-2011.html

Alternatively, you can use what is in this post and then pass it to FetchXML to request the same information. If you do, it will help too ...

http://blog.customereffective.com/blog/2011/05/parsing-and-consuming-the-crm-2011-soap-service-inside-javascript.html

0
source

All Articles