How do I preserve line breaks when converting multi-line text field to rich text field?

  • 0
  • 1
  • Question
  • Updated 10 months ago
  • In Progress
  • (Edited)
We have a few thousand records in a table with a multi-line text field. The data in the text field often has lines breaks in order to make the content easier to read, some of them containing lists for example. I'd like to switch the field format to rich text primarily to allow users to make use of proper bullet points but I notice that when converting the fields, all of the existing line breaks are lost. Unfortunately there are far too many to manually fix after to conversion. Does anyone have an idea as to how the line breaks could be preserved?


Example content stored in multi-line text field:


From: MealPal [mailto:hello@mealpal.co.uk
Sent: 24 January 2018 11:16
To: Kipp
Subject: New Restaurant Alert


Same content after converting to rich-text field (loses the line breaks):

From: MealPal [mailto:hello@mealpal.co.uk] Sent: 24 January 2018 11:16To: KippSubject: New Restaurant Alert
Photo of Kipp

Kipp

  • 258 Points 250 badge 2x thumb
  • excited

Posted 10 months ago

  • 0
  • 1
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 26,472 Points 20k badge 2x thumb
You need to replace each newline character (ie \n) in the Text field with <br > tags in the Rich Text field. This can be done with script using the general procedure used in this Pastie:

How To Globally Replace String In Text Field Automatically?
https://community.quickbase.com/quickbase/topics/how-to-globally-replace-string-in-text-field-automa...

Here is a screenshot of me editing a modified record after manually applying similar code from the console:



As this code could  modify every record in a table you should only use it if you are comfortable with using JavaScript. I would further suggest you work in a copy of your production application.

If you need personalized assistance you can contact me via the information in my profile:

https://community.quickbase.com/quickbase/people/dandiebolt
(Edited)