Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

javascript SOAP retrieve contact records by contactid - network error

$
0
0

hi, when I try retreive contact record with this method I have a NetworkError. What is wrong with this methods ?

function ExecuteRequest(soapBody, method) {
    try {
        var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
        xmlHttpRequest.Open("POST", '/mscrmservices/2007/CrmService.asmx', false);
        xmlHttpRequest.setRequestHeader("SOAPAction", 'http://schemas.microsoft.com/crm/2007/WebServices/' + method); //Fetch,Execute,Create
        xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
        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>" + soapBody + "</soap:Body></soap:Envelope>";
        xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
        xmlHttpRequest.send(xml);

        var resultXml = xmlHttpRequest.responseXML;
        var errorCount = resultXml.selectNodes('//error').length;
        var status = xmlHttpRequest.status;

        if (errorCount != 0) {
            var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
            alert(msg);

            return null;
        }

        return resultXml;
    }
    catch (err) {
    }

    return null;
}

function GetContact(contactID) {

    var request = "<s:Envelope xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'>" +"<s:Body>" +"<RetrieveMultiple xmlns='http://schemas.microsoft.com/xrm/2011/Contracts/Services'     xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>" +"<query i:type='a:QueryExpression' xmlns:a='http://schemas.microsoft.com/xrm/2011/Contracts'>" +"<a:ColumnSet>" +"<a:AllColumns>false</a:AllColumns>" +"<a:Columns xmlns:b='http://schemas.microsoft.com/2003/10/Serialization/Arrays'>" +"<b:string>fullname</b:string>" +"<b:string>mobilephone</b:string>" +"<b:string>emailaddress1</b:string>" +"<b:string>telephone2</b:string>" +"</a:Columns>" +"</a:ColumnSet>" +"<a:Criteria>" +"<a:Conditions>" +"<a:ConditionExpression>" +"<a:AttributeName>contactid</a:AttributeName>" +"<a:Operator>Equal</a:Operator>" +"<a:Values xmlns:b='http://schemas.microsoft.com/2003/10/Serialization/Arrays'>" +"<b:anyType i:type='c:string' xmlns:c='http://www.w3.org/2001/XMLSchema'>" + contactID + "</b:anyType>" +"</a:Values>" +"</a:ConditionExpression>" +"</a:Conditions>" +"<a:FilterOperator>And</a:FilterOperator>" +"<a:Filters />" +"</a:Criteria>" +"<a:Distinct>false</a:Distinct>" +"<a:EntityName>contact</a:EntityName>" +"<a:LinkEntities />" +"<a:Orders />" +"<a:PageInfo>" +"<a:Count>0</a:Count>" +"<a:PageNumber>0</a:PageNumber>" +"<a:PagingCookie i:nil='true' />" +"<a:ReturnTotalRecordCount>true</a:ReturnTotalRecordCount>" +"</a:PageInfo>" +"<a:NoLock>false</a:NoLock>" +"</query>" +"</RetrieveMultiple>" +"</s:Body>" +"</s:Envelope>";

    var _ResultXML = ExecuteRequest(request, "RetrieveMultiple");
    var count = _ResultXML.selectSingleNode("//a:TotalRecordCount").text;
    if (count >= 1) {
        var fullName = _ResultXML.selectSingleNode("//a:fullname").text;
        var mobPhone = _ResultXML.selectSingleNode("//a:mobilephone").text;
        var email = _ResultXML.selectSingleNode("//a:emailaddress1").text;
        var tel = _ResultXML.selectSingleNode("//a:telephone2").text;
}


Viewing all articles
Browse latest Browse all 8223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>