locked
How to query using FetchXML by JavaScript on Dynamics CRM 2011? RRS feed

  • 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>&lt;fetch mapping='logical'&gt;" +
    "&lt;entity name='email'&gt;" +
    "&lt;link-entity name='activityparty' from='activityid' to='activityid' link-type='inner'&gt;" +
    "&lt;attribute name='partyid'/&gt;" +
      //"&lt;attribute name='partyidname'/&gt;"+
    "&lt;filter type='and'&gt;" +
    "&lt;condition attribute='activityid' operator='eq' value='" + originalEmailId + "'/&gt;" +
    "&lt;condition attribute='partyobjecttypecode' operator='eq' value='2020'/&gt;" +
    "&lt;condition attribute='participationtypemask' operator='eq' value='2'/&gt;" +
    "&lt;/filter&gt;" +
    "&lt;/link-entity&gt;" +
    "&lt;/entity&gt;" +
    "&lt;/fetch&gt;</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('&lt;', '<');
        resultSet.replace('&gt;', '>');
    
        // 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

All replies