Answered by:
How to query using FetchXML by JavaScript on Dynamics CRM 2011?

Question
-
Hi All,
I am new comer in Dynamics CRM 2011, i want to know how to do query in Dynamics CRM 2011 using FetchXML by javascript? in v4.0 i can do this script for query records the entity :
//Where a new email is a reply, get the 1st queue in the originating email's 'To' partylist, where one exists. function getOriginatingEmailFirstQueue(originalEmailId) { var authenticationHeader = GenerateAuthenticationHeader(); // Prepare the SOAP message. //PartyObjectTypeCode of 2020 = queue, ParticipationTypeMask of 2 = 'To' 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'>" + authenticationHeader + "<soap:Body>" + "<Fetch xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" + "<fetchXml><fetch mapping='logical'>" + "<entity name='email'>" + "<link-entity name='activityparty' from='activityid' to='activityid' link-type='inner'>" + "<attribute name='partyid'/>" + //"<attribute name='partyidname'/>"+ "<filter type='and'>" + "<condition attribute='activityid' operator='eq' value='" + originalEmailId + "'/>" + "<condition attribute='partyobjecttypecode' operator='eq' value='2020'/>" + "<condition attribute='participationtypemask' operator='eq' value='2'/>" + "</filter>" + "</link-entity>" + "</entity>" + "</fetch></fetchXml>" + "</Fetch>" + "</soap:Body>" + "</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/Fetch"); 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); return null; } // Process and display the results. else { // Capture the result and UnEncode it. var resultSet = new String(); resultSet = resultXml.text; resultSet.replace('<', '<'); resultSet.replace('>', '>'); // Create an XML document that you can parse. var oXmlDoc = new ActiveXObject("Microsoft.XMLDOM"); oXmlDoc.async = false; // Load the XML document that has the UnEncoded results. oXmlDoc.loadXML(resultSet); // Display the results. var results = oXmlDoc.getElementsByTagName('result'); var queue = results[0].selectSingleNode('./activityid.partyid').nodeTypedValue; var queueName = results[0].selectSingleNode('./activityid.partyid').getAttribute('name'); if (queue != null && queue.length > 0) { queue = queue.replace('{', '').replace('}', ''); //Create an array to set as the DataValue for the lookup control. var lookupData = new Array(); //Create an Object add to the array. var lookupItem = new Object(); //Set the id, typename, and name properties to the object. lookupItem.id = '{' + queue + '}'; lookupItem.typename = 'queue'; lookupItem.name = queueName; // Add the object to the array. lookupData[0] = lookupItem; // Set the value of the lookup field to the value of the array. crmForm.all.from.DataValue = lookupData; return true; } else { alert('no queue - is null'); return null; } } }
please advise,thanks,
Rory Glo.
Monday, November 28, 2011 3:13 AM
Answers
-
have a look at this buddy
http://blog.customereffective.com/blog/2011/05/execute-fetch-from-javascript-in-crm-2011.html
I hope this helps.
If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Amreek Singh Senior CRM Consultant CDC Praxa Sydney, Australia http://mscrmshop.blogspot.com http://crm2011usersettings.codeplex.com- Proposed as answer by Amreek Singh Monday, November 28, 2011 3:53 AM
- Marked as answer by pntr Monday, November 28, 2011 7:21 AM
Monday, November 28, 2011 3:53 AM
All replies
-
have a look at this buddy
http://blog.customereffective.com/blog/2011/05/execute-fetch-from-javascript-in-crm-2011.html
I hope this helps.
If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Amreek Singh Senior CRM Consultant CDC Praxa Sydney, Australia http://mscrmshop.blogspot.com http://crm2011usersettings.codeplex.com- Proposed as answer by Amreek Singh Monday, November 28, 2011 3:53 AM
- Marked as answer by pntr Monday, November 28, 2011 7:21 AM
Monday, November 28, 2011 3:53 AM -
Hi Amreek,
Thanks for the link its very helpfully.
-Rory Glo
Monday, November 28, 2011 7:21 AM -
These links are overkill.
In black and white, why can't there be a simple solution to do this where minimal code is replaced?
Friday, June 7, 2013 3:28 PM -
These links are overkill.
In black and white, why can't there be a simple solution to do this where minimal code is replaced?
Wednesday, July 3, 2013 12:40 PM