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

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 365 | Integration, Dataverse, and general topics

#1
Siv Sagar Profile Picture

Siv Sagar 93 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 80

#3
Martin Dráb Profile Picture

Martin Dráb 64 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans