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

how to get contact email in crm 2013

$
0
0

Hi,

I have created an entity and its contact lookup field. I want to get contact email address on lookup field change event. I have created a script but its not working in CRM 2013. Kindly tell me whats the issue in my script

function getContactId() {

    var authenticationHeader, xml, xHReq;

    var resultXml, errorCount, msg, returnValue, returnId;




if(Xrm.Page.context.getClientUrl)//Post UR 12
{
    authenticationHeader = Xrm.Page.context.getClientUrl();
}
else//Pre UR 12
{
    authenticationHeader = Xrm.Page.context.getServerUrl();
}

    var contact = new Array();




    contact = Xrm.Page.getAttribute("primarycontactid").getValue();

    //alert(contact[0].id.toString());

    //alert(contact[0].name);




    // Define the SOAP XML to access Microsoft Dynamics CRM Web service.

    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>" +

    // Specify the RetrieveMultiple message.

        "<RetrieveMultiple xmlns=" +

        "\"http://schemas.microsoft.com/crm/2007/WebServices\">" +

    // Specify that this is a QueryByAttribute query.

        "<query xmlns:q1=" +

        "\"http://schemas.microsoft.com/crm/2006/Query\" " +

        "xsi:type=\"q1:QueryByAttribute\">" +

    // Query the customeraddress entity.

        "<q1:EntityName>contact</q1:EntityName>" +

    // Set the columns you want to return.

        "<q1:ColumnSet xsi:type=\"q1:ColumnSet\">" +

        "<q1:Attributes>" +

        "<q1:Attribute>emailaddress1</q1:Attribute>" +




        "</q1:Attributes>" +

        "</q1:ColumnSet>" +

    // Specify the attribute that you are querying on.

        "<q1:Attributes>" +

        "<q1:Attribute>contactid</q1:Attribute>" +

        "</q1:Attributes>" +

    // Set the value of the attribute using the customerid

    // value of the case record.

        "<q1:Values>" +

        "<q1:Value xsi:type=\"xsd:string\">" +

        contact[0].id +

        "</q1:Value>" +

        "</q1:Values>" +

        "</query>" +

        "</RetrieveMultiple>" +

        "</soap:Body>" +

        "</soap:Envelope>";




    // Create an instance of an XMLHTTP object.

    xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");

    // Configure the XMLHttp object for the Microsoft CRM Web services.

    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

        );

    // Send the XMLHttp request.

    xmlHttpRequest.send(xml);

    // Capture the XMLHttp response in XML format.

    resultXml = xmlHttpRequest.responseXML;




    errorCount = resultXml.selectNodes('//error').length;

    // alert(errorCount.toString());

    if (errorCount != 0) {

        msg = resultXml.selectSingleNode('//description').nodeTypedValue;

        alert("An error has been occured on loading Customer Information\nError Details: " + msg);

    }

    else {

        if (resultXml.selectNodes("//q1:emailaddress1") != null) {




            var req = resultXml.selectSingleNode("//q1:emailaddress1").nodeTypedValue;

            Xrm.Page.getAttribute("emailaddress1").setValue(req);

        }

        else {

            alert("CRM 2011 encountered an error while fetching for email address");

        }

    }

}


Viewing all articles
Browse latest Browse all 8223

Trending Articles



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