web
You’re offline. This is a read only version of the page.
close
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

I have the same question (0)
  • Verified answer
    Hosk Profile Picture
    on at

    What is the error you are getting?

    I would recommend you Press F12 and step through the Javascript code so you can see where the code errors and then fix it.

    The code you have written is unsupported in Microsoft CRM (you are not allowed to access the document).

    You could run a plugin on the create of the email and create a new field with stripped out tags.

    C# code

    aliraza.wordpress.com/.../how-to-remove-html-tags-from-string-in-c

    A sample plugin

    blogs.msdn.com/.../converting-html-e-mail-to-plain-text.aspx

  • Suggested answer
    Hosk Profile Picture
    on at

    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

  • jagathsb Profile Picture
    70 on at

    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
    Community Member Profile Picture
    on at

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


  • Community Member Profile Picture
    on at

    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.

  • Community Member Profile Picture
    on at

    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.

  • TomSmelser Profile Picture
    1,570 on at

    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

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

  • crmuser123 Profile Picture
    10 on at

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

  • TomSmelser Profile Picture
    1,570 on at

    Hello,

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

    Thank you,

    Tom

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans