Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

remove html from the e-mail description when creating a case

(0) ShareShare
ReportReport
Posted on by

I have done numerous google searches and research on the topic but can’t find a working solution.

I’m creating a case in CRM 2011 (on premises) directly from an email tracked in outlook. The description shows all the html aswell has the text.

I have tried the following code on the cases form (onload) but I just get an error .

function OnCrmPageLoad()

{

 //Create a factitious DOM element

 var stubDescription = document.createElement( "<SPAN style='width:1px;height:1px'>");

 //This field contains the email body (HTML)

 var description = crmForm.all.description;

 //Assign the HTML to the factitious DOM element

 stubDescription.innerHTML = description.DataValue;

 //Add it to the html document

 document.body.appendChild( stubDescription );

 //Assign the stripped body back to the description field

 description.DataValue = stubDescription.innerText;

 //remove the factitious DOM element

 document.body.removeChild( stubDescription );

}

//Entry Point

OnCrmPageLoad();

Paul Johnson

*This post is locked for comments

  • Suggested answer
    Pradip Raj Profile Picture
    327 on at
    RE: remove html from the e-mail description when creating a case

    Now it is possible to copy contents of email body to Case description. Please check my comment in below article.

    community.dynamics.com/.../1116274

    Thanks

    Pradip

  • TomSmelser Profile Picture
    1,570 on at
    RE: remove html from the e-mail description when creating a case

    Hello,

    Just wondering which method you used. c# or js ?

    Thank you,

    Tom

  • crmuser123 Profile Picture
    10 on at
    RE: remove html from the e-mail description when creating a case

    Wonderful. I searched many articles but this worked wonderuflly.  Thanks for the great work.

  • Community Member Profile Picture
    on at
    RE: remove html from the e-mail description when creating a case

    Thanks Tom, appreciate your help. I'll take a look at these.

  • TomSmelser Profile Picture
    1,570 on at
    RE: remove html from the e-mail description when creating a case

    Sally,

    Jason Lattimer has a set of string utilities that includes a RegExReplace function.

    community.dynamics.com/.../crm-string-workflow-utilities

    That in combination with the regex for replacing tags in a string may work.

    Worth a try. But I will admit I have never used it this way.

    Good Luck!

    stackoverflow.com/.../using-c-sharp-regular-expressions-to-remove-html-tags

  • Community Member Profile Picture
    on at
    RE: remove html from the e-mail description when creating a case

    Does anyone have any suggestions on JS that will work to remove the HTML tags in the Lead Description field, after auto-creating a record from an email?

    Alternatively, if you have a working and production-ready plugin that I could use or purchase, I'd be open to that!

    Many thanks in advance.

  • Community Member Profile Picture
    on at
    RE: remove html from the e-mail description when creating a case

    Hi, I've followed the sample code above from Rajeev, and created a JS web resource with this code, and attached it to the Lead onFormLoad event on the main form. However, it still does not appear to strip the HTML from the Description field on page load. Any ideas how I can determine what the issue is or is there updated code that might work? I am more experienced with JS rather than writing a server-side plugin.

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: remove html from the e-mail description when creating a case

    Try this for CRM 2011 onwards.

    //Function to remove the HTML tags from the description field.
    function onFormLoad() {
       
        //This field contains the email body (HTML) 
        var description = Xrm.Page.getAttribute("description").getValue();
        if (description != null && (description.indexOf("html")!=-1 || description.indexOf("HTML")!=-1)){
            //Create a factitious DOM element 
            var stubDescription = document.createElement("span");
            stubDescription.width = "1px";
            stubDescription.height = "1px";
            //Assign the HTML to the factitious DOM element 
            stubDescription.innerHTML = description;
            //Add it to the html document 
            document.body.appendChild(stubDescription);
            //Assign the stripped body back to the description field 
            description = stubDescription.innerText;
    
            Xrm.Page.getAttribute("description").setValue(description);
            //remove the factitious DOM element 
            document.body.removeChild(stubDescription);
        }
          
    }


  • jagathsb Profile Picture
    70 on at
    RE: remove html from the e-mail description when creating a case

    HI All,

     

    I am want to use an Jscript to perform the Stripping HTML Tags From an Email, and use an work flow or the auto case creation rule to copy the description to the case Description, this part is fine and it work but with HTML Tags.

    The issue I have is Stripping HTML Tags from an Email, I have used the below, as mentioned in the link http://mscrm4ever.blogspot.co.uk/2008/08/stripping-html-tags-from-email.html , but this is not suitable for CRM 2015/2016, any suggestion how this could be amended to set to 2015/2016.

     

    function OnCrmPageLoad()

    {

      //Create a factitious DOM element

      var stubDescription = document.createElement( "<SPAN style='width:1px;height:1px'>");

      //This field contains the email body (HTML)

      var description = crmForm.all.description;

      //Assign the HTML to the factitious DOM element

      stubDescription.innerHTML = description.DataValue;

      //Add it to the html document

      document.body.appendChild( stubDescription );

      //Assign the stripped body back to the description field

      description.DataValue = stubDescription.innerText;

      //remove the factitious DOM element

      document.body.removeChild( stubDescription );

    }

     

    //Entry Point 

  • Suggested answer
    Hosk Profile Picture
    on at
    RE: remove html from the e-mail description when creating a case

    This video will show you how to do it

    www.youtube.com/watch

    Also this blog post is excellent

    ashwaniashwin.wordpress.com/.../convert-html-to-plain-text-for-copying-email-message-in-crm-2011-2013

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,280 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,034 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans