locked
Get Particular node value in array from xml RRS feed

  • Question

  • I use the Following code for Retrieve All opportunity guid from entity.

    function guid(){ 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\">" + GenerateAuthenticationHeader() + "<soap:Body>" + "<RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" + "<query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\">" + "<q1:EntityName>opportunity </q1:EntityName>" + "<q1:ColumnSet xsi:type='q1:ColumnSet'>" + "<q1:Attributes>" + "<q1:Attribute>opportunity id</q1:Attribute>" + "</q1:Attributes>" + "</q1:ColumnSet>" + "<q1:Distinct>false</q1:Distinct>" + "</query></RetrieveMultiple>" + "</soap:Body></soap:Envelope>"; var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP"); xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false); xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple"); xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); xmlHttpRequest.setRequestHeader("Content-Length", xml.length); xmlHttpRequest.send(xml); var result = xmlHttpRequest.responseXML.xml; var doc = new ActiveXObject("MSXML2.DOMDocument"); doc.async = false; doc.loadXML(result); }

    Output like,

    Here the result variable contains the xml Values.I need to form an array with opportunityid.

    which means take all opportunityid from the result xml variable and form in array?How to do this?


    Tuesday, November 18, 2014 11:13 AM

All replies

  • var arrayAnswers = [];
    var arr = doc.selectNodes("//q1:opportunityid"); 
        for(var i=0, len = arr.length; i < len; i++)
        {
    		
           arrayAnswers[i] = arr.nextNode.text;
    
        }
    	
    	
    	alert(arrayAnswers);

    Regards, Saad

    Thursday, November 27, 2014 5:53 AM
  • Saad,It shows Empty Value
    Thursday, November 27, 2014 7:16 AM
  • Share your full code.

    Regards, Saad

    Thursday, November 27, 2014 7:19 AM
  • Mark it as answered so others can refer it too.

    Regards, Saad

    Thursday, November 27, 2014 7:28 AM