Set default font face in TinyMCE

Alex G_
Tera Contributor

Hello everyone,

 

many ServiceNow developers have encountered the problem of why you can't change the default font size in tinymce (html fields). The default size is 8pt and there are several ideas, including a few articles from ServiceNow, one of which says that there is no such feature in the system, another says about a workaround that recommends to put a default value in the field.

 

I'm not sure, but I may have found a more elegant solution using the internal functionality of tinymce itself. To do this, we all need to find all the containers on the page and set the font size value. Before version 6 this was possible via tinymcy.editors. But since version 6 this parameter is deprecated and we need to use tinymcy.get().

 

What needs to be done:

 

1. Create OnLoad client script (table sys_script_client)
2. And put this simple, very small, code

 

function onLoad() {

	window.addEventListener('load', () => {
	
		var tinymceDivs = document.getElementsByClassName('tox tox-tinymce');

		for (var i = 0; i < tinymceDivs.length; i++) {
			var editor = tinyMCE.get(i);
			editor.getBody().style.fontSize = '10pt';
		}

	});
}

 

You can of course use .get() with the exact name of the container (textarea id). But in my case everything needed a global solution for all pages. Search for div wit class “tox-tinymce”, give the number of containers initialized on the page.

 

AlexG__0-1750946746589.png

Good luck!

3 REPLIES 3

Brian Lancaster
Tera Sage

This will only work in the Standard UI. If you are using SOW it will not work however I have noted that in SOW the default font size is already 10. At least that is what is show in problem when I check on my company instance and we don't have any script setup.

You're absolutely right – the script only works in the Standard UI. And as you correctly pointed out, in SOW the default font size is already set to 10pt, so there's no need for the script there anyway. Thanks for confirming!

Unless you want a 12pt font. Like we set it all are notification.