HTML fields and line spacing

wiltonr
Giga Contributor

Is there any way to set the default line spacing on HTML fields?   I've seen posts about writing a before Business Rule to replace the HTML tags but that doesn't change it until you save the record.

I created an HTML field on the sys_user table to allow ITIL users to create a personal signature, which we can pull in to the email client.   Originally I created it as a string field but it did not put any line breaks at all so the signature would all end up on one line so I changed it to be an HTML field.   When the user goes to My Profile to add their signature, everything is double spaced.   The only way to single space is to Shift+Enter for a line break, but I don't want the ITIL users to have to remember to do that.  

When the carriage return is used, it adds a </p> tag.   If I could get it to add the <br /> tag it would single space.   Does anyone know of a way to do this so that it will always single space in the HTML field in real-time the user is entering their information?

9 REPLIES 9

geoffcox
Giga Guru

Why not just use a before update business rule to remove paragraph tags and replace them with line breaks?


tltoulson
Kilo Sage

Hi Rhonda,



This may or may not work with your configuration.   I am running Eureka using TinyMCE4 for the HTML Editor and have tested it with this configuration.   Try creating a client script on load for your form:



function onLoad() {


  //Type appropriate comment here, and begin script below


  addAfterPageLoadedEvent(function() {


  tinymce.EditorManager.editors[0].settings.force_br_newlines = true;


  tinymce.EditorManager.editors[0].settings.force_p_newlines = false;


  tinymce.EditorManager.editors[0].settings.forced_root_block = "";


  });


}



This client script will create an event that runs after the page is fully loaded, giving the TinyMCE editor a chance to initialize.   It then selects the first TinyMCE editor instance and changes it settings to output <br> tags instead of <p> tags.   Usually, TinyMCE prefers all this to be setup at initialization time (something we don't have access to in ServiceNow) but this appears to hack it in as gracefully as possible.



Please let me know if this works out for you.



Kind regards,



Travis


Hi Tltoulson,

I tried above client script in one of the form(Story). It worked fine, reduce the line space between text.

Is there anyway apply this script in all forms which has HTML field instead of going to every table one by one.

Thanks.

Slava Savitsky
Giga Sage

In fact, force_br_newline and force_p_newline are deprecated in the TinyMCE v4, so it might be enough to set forced_root_block to false or an empty string.