web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

HTML to Plain Text Conversion Issue

(0) ShareShare
ReportReport
Posted on by 31

Hello,

I have been working on a custom workflow where I move the content of an email description field to a case description field, as I effectively convert an email to a case. Have had the common issue where this then originally comes back in HTML formatting with endless tags which then make the case field impossible to read.

With Jason Lattimer's magnificent string workflow solutions, I have converted the field content so it would read something like "Dear Person, <br> Here is my email <br> from Person". His workflows leave in line breaks deliberately, but is there any simple way I could then turn this into:

"Dear Person

Here is my email

from Person"

Could I find and replace the "<br>" to something else for example that would force this? I had followed this description but it just replaces the <br> with double spaces, rather than forcing new lines..

https://community.dynamics.com/crm/b/meganwalker/posts/removing-html-from-email-description-record-creation-rules

Any help would be most appreciated! I am rather new to Dynamics!

Thanks,

Jon

I have the same question (0)
  • Suggested answer
    T.I.A Profile Picture
    1,760 on at

    HI Jmills

    You should be able to replace the breaks with \n.

    Example: string html = "Dear Person <br>Here is my email<br>from Person";

                  string newString = html.Replace("<br>", "\n\n");

                  case["example_description"] = newString;

                  service.Update(case);

    I've tried this with a multiple line of text field and it works fine. Let me know how you go.

  • jmillsjmills Profile Picture
    31 on at

    Amazing. Thank you for your reply! Sorry to be silly - where could I actually implement this within the workflow user interface of Dynamics?

  • T.I.A Profile Picture
    1,760 on at

    Ah you can't unless you implement this part in a custom workflow activity via C#.

  • Suggested answer
    cloflyMao Profile Picture
    25,210 on at

    Hi jmill,

    That's because the workflow tool you use will insert all contents directly as text without characters conversion even if we can replace all br tags with our own symbols by regex.

    I suggest you could insert a javascript web resource into Case form and do conversion of "br to real new line" when the form on load, this process is rapid, 

    and I thought it would require less job than custom workflow.

    function formatDescription(executionContext) {
      var formContext = executionContext.getFormContext();
      var val = formContext.getAttribute("description").getValue();
      var newVal = val.replace(//gi, "\n");
      formContext.getAttribute("description").setValue(newVal);
    }

    Email content:

    pastedimage1575264235529v1.png

    Case description after executed js function:

    pastedimage1575264272604v2.png

    Regards,

    Clofly

  • jmillsjmills Profile Picture
    31 on at

    Hello! This looks fantastic, and quite a bit simpler. Thank you! I have added the resource to the resource library and set it to run "OnLoad" but I am currently getting a script error. The code runs fine in an online Javascript validator, but unfortunately I get "ReferenceError: ConvertLineBreaks is not defined at eval (eval at RunHandlerInternal). Any further thoughts there at all pretty please? What could I be missing?

  • cloflyMao Profile Picture
    25,210 on at

    Hi jmill,

    Could you share me your form properties settings?

    Below is mine:

    pastedimage1575281797168v1.png

    Have you checked the option below for formatting function?

    pastedimage1575281842158v2.png

    What's more, it would be better if you could share your original description with br tag in Case form.

    Also, please try to use T.I.A's anwser to test again:

    var newVal = val.replace("<br>", "\n"); if your br tag is <br> instead of <br/>

    Regards,

    Clofly

  • jmillsjmills Profile Picture
    31 on at

    Hello! Thank you so much for your swift reply. Much appreciated!

    Yes - so this is the script error... (and you can see the original description in the background).

    CRM-Screenshot-1.PNG

    This is my form libraries:

    CRM-Screenshot-2.PNG

    I didn't have this tickbox checked, but then I did tick it and it still produces the same script error (having published all customisations).

    error_2D00_02.PNG

    And this is what i have in the web resource content:

    CRM-Screenshot-4.PNG

    Thanks very much! I'm very appreciative of your help.

  • Verified answer
    cloflyMao Profile Picture
    25,210 on at

    Hi Jmill,

    Yes, please tick the tickbox.

    From your error and screenshot, there is no function called ConvertLineBreaks.

    You're calling a function called ConvertLineBreaks

    pastedimage1575289071547v1.png

    However, my function name is formatDescription.

    pastedimage1575289136413v3.png

    So you should change it to ConvertLineBreaks, that's your own function name.

    Regards,

    Clofly

  • jmillsjmills Profile Picture
    31 on at

    Clofly that is absolutely fantastic! Thank you so much. I really appreciate you walking me through that so simply, and I have managed to get the result I was after.

    Thank you so much again! You're a true legend of the Dynamics world in my view now!

    Regards,

    Jon

  • jmillsjmills Profile Picture
    31 on at

    Hello Clofly! Hoping you're still around. Is there anything I can add to your JS so that it won't run if the field it's looking for is blank?

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
11manish Profile Picture

11manish 156

#2
Pallavi Phade Profile Picture

Pallavi Phade 102 Super User 2026 Season 1

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 55 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans