1

I'm trying to parse the response from a XMLHttpRequest using XrmServiceToolkit for CRM 2015. The code for parsing the results is working fine in IE 11, however it is not working as expected in Chrome. Please assist.

Here are the details :

var requestMain = ""
    requestMain += "      <request i:type=\"b:RetrieveRecordChangeHistoryRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\" xmlns:b=\"http://schemas.microsoft.com/crm/2011/Contracts\">";
    requestMain += "        <a:Parameters xmlns:c=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
    requestMain += "          <a:KeyValuePairOfstringanyType>";
    requestMain += "            <c:key>Target</c:key>";
    requestMain += "            <c:value i:type=\"a:EntityReference\">";
    requestMain += "              <a:Id>" + entityId + "</a:Id>";
    requestMain += "              <a:LogicalName>" + entityName + "</a:LogicalName>";
    requestMain += "              <a:Name i:nil=\"true\" />";
    requestMain += "            </c:value>";
    requestMain += "          </a:KeyValuePairOfstringanyType>";
    requestMain += "        </a:Parameters>";
    requestMain += "        <a:RequestId i:nil=\"true\" />";
    requestMain += "        <a:RequestName>RetrieveRecordChangeHistory</a:RequestName>";
    requestMain += "      </request>";

var changeHistoryResponse = XrmServiceToolkit.Soap.Execute(requestMain);
var results = changeHistoryResponse.getElementsByTagName("a:Results")[0];

...

var auditRecords = results.childNodes[0].childNodes[1].getElementsByTagName("b:AuditDetail");

The line changeHistoryResponse.getElementsByTagName("a:Results")[0]; is working fine in IE, however it returns null in Chrome. Because of this the other part of the code is throwing error

var auditRecords = results.childNodes[0].childNodes[1].getElementsByTagName("b:AuditDetail");

Cannot read property 'childNodes' of undefined

Cerbrus
  • 70,800
  • 18
  • 132
  • 147
Rajesh
  • 449
  • 2
  • 9
  • 22
  • 1
    Please don't use snippets if the code doesn't actually need to run in the question. – Cerbrus Sep 11 '15 at 06:38
  • 1
    i think you should use `getElementsByTagNameNS('a:Results')` in chrome if you want to include the namespace, otherwise you could use `getElementsByTagName('Results')` – Icepickle Sep 11 '15 at 06:39
  • possible duplicate of [cross-browser 'getElementsByTagName' with namespace from responseXML](http://stackoverflow.com/questions/17486882/cross-browser-getelementsbytagname-with-namespace-from-responsexml) – Icepickle Sep 11 '15 at 06:46
  • 1
    Thanks @Icepickle getElementsByTagName('Results') worked fine. – Rajesh Sep 11 '15 at 12:57
  • 1
    @Cerbrus - Going forward, I will ensure to use sample code instead of snippets. Thanks – Rajesh Sep 11 '15 at 12:59

0 Answers0