locked
How to receive email body out of webservice RRS feed

  • Question

  • Hi,

    I am trying to remove html tags from the email received in CRM through webserbice. I do onload event when I open email. Basic idea is when you open email, what will happen is funciton kicks off and it will read the description (body of email)..It uses webservice to retrievew email body.

    What I don’t get in place is I don’t ger results! I do a call and I should get a response. I don’t receive attribute out of webservice..  Where am I going wrong here with my code?????

    Any help would be much appreciated. Thanks so much..   below is the code:

    function launchModalDialog(dialogID, typeName, recordId) {

                    // load modal

                    var serverUri = Mscrm.CrmUri.create('/cs/dialog/rundialog.aspx');

                   

                    window.showModalDialog(serverUri + '?DialogId=' + dialogID + '&EntityName' + typeName + '&ObjectId=' + recrodId, null, 'with=615,height=480,resizable=1,status=1,scrollbars=1');

                   

                    //Reload form

                    window.location.reload(true);

    }

    function stripHTML(html) {

       return html.replace(/<[^>]*>?/g, "");

    }

    function setPlainText() {

                    var strGUID = Xrm.Page.data.entity.getId();

        var authenticationHeader = Xrm.Page.context.getAuthenticationHeader();

        //Prepare the SOAP message.

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

    "<Retrieve xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +

    "<entityName>email</entityName>" +

    "<id>" + strGUID + "</id>" +

    "<columnSet xmlns:q1='http://schemas.microsoft.com/crm/2006/Query' xsi:type='q1:ColumnSet'>" +

    "<q1:Attributes>" +

    "<q1:Attribute>sp_bodyplaintext</q1:Attribute>"

    "</q1:Attributes>" +

    "</columnSet>" +

    "</Retrieve>" +

    "</soap:Body>" +

    "</soap:Envelope>";

    alert(xml); //debug

        //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/Retrieve");

        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);

        }

        //Display the retrieved value.

        else {

            var strDescription = resultXml.selectSingleNode("//q1:sp_bodyplaintext");

                                    if (strDescription == null){

                                                    alert("Email is empty"); //alert

                                    }             

                                    else {

                                                    var strPlainText = stripHTML(strDescription.nodeTypedValue);

                                                    alert(strPlainText); // debug

                                                    Xrm.Page.getAttribute('sp_bodyplaintext').setValue(strPlainText);

                                    }

        }

    }

    function runMeetingNoteDialog()

    // the actual function that cleans the HTML Tags and runs the dialogue session

    {

                    // remove HTML tags

                    setPlainText();

                    // save updated record

    //            Xrm.Page.data.entity.save;

    //            crmForm.Save();

    }

    Thursday, March 27, 2014 5:58 PM

All replies

  • First, which version of CRM are you using ? Your code uses the CRM 4.0 endpoint, so won't work in CRM 2013, but should work in CRM 4.0 or CRM 2011 (but not necessarily in all browsers as you're using the Msxml2.XMLHTTP object.

    Can you clarify what is returned ? Do you get xml in xHReq.responseXML or not ? If so, do you get an entity record, and if so, what attributes are in it ?

    Something else to consider: Have you stripped all HTML tags in your sp_bodyplaintext attribute ? CRM should encode the data correctly for XML, but you may get an encoding problem if you have some tags in the data


    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    Thursday, March 27, 2014 8:23 PM
    Moderator