Jim Coyne
Kilo Patron
Part of the Developer Toolbox Series.

 

Related Tools:

"Expand Article Editor +" Tool for KB Articles

"Expand Message HTML Editor +" Tool for Email Notifications

 

Here's a tool to help Email Template editors expand the Message HTML editor to a useful size.

 

The Message HTML field is of type html_script and is a little bit different from the html and translated_html types, but the  -  and  +  icons at the top-right of the control will change the height of the control as well:

 

JimCoyne_0-1692445357662.png

 

Clicking either icon will change the height AND create/update a User Preference record for that particular field.

 

The  +  icon allows users to expand the height of the control, but for some reason is limited to a maximum height of either just 435 pixels, or whatever is listed in the User Preference record for the field, whichever is greater.  Now the User Preference record is only set by both of those icons when they are clicked or the resize control, so there's not much flexibility in how to set that preference.  The resize control at the bottom-right of the control is also limited to those maximums (although it seems to remember the largest height the user has used: not sure):

 

JimCoyne_1-1692445811181.png

 

So I created a Form button UI Action that will simply keep adding 60 pixels to the height of the control without limits:

 

JimCoyne_2-1692445987219.png

 

I use 60 because that is also what the  -  and  +  icons use.  The  +  icon may not be active when the maximum height is reached, but the UI Action still is.  It will expand the editor and create/update the User Preference record so that the height remains the same the next time you open a record.

 

Here are the UI Action details:

Name:            Expand Message HTML Editor +

Table:           Email Template [sysevent_email_template]

Order:           -1,000

Action name:     u_fpc_expand_message_html_editor

Hint:            Expand the height of the Message HTML editor (FPC)

Form button:     Checked

Onclick:         uFpcExpandMessageHtmlEditor();

Isolate script:  false    VERY IMPORTANT, may have to switch to List view to set

Script:

 

function uFpcExpandMessageHtmlEditor() {
	var tableName = g_form.getTableName();
	var fieldName = "message_html";
	var fullFieldName = tableName + "." + fieldName;
	var change = 60;
	var preferenceName = "tinymce_height." + fullFieldName;

	//find the div via the field label (not the best way)
	var editor = document.getElementById("element." + fullFieldName);
	if (editor) {
		var div = editor.querySelector('[role="application"]');
		if (div) {
			var height = parseInt(div.style.height) || 300;  //default to 300 if we can't get the height for some reason
			var newHeight = height + change;

			//expand the height of the div
			div.style.height = newHeight + "px";

			//then save the height for next time
			setPreference(preferenceName, newHeight);
		}
	}
}

 

NOTE:  It seems, in versions prior to Vancouver, the maximum height of 435 is used when a record is reloaded instead of the new value in the User Preference.  You can expand the control again, but that 435 limit will be used the next time a record is opened.

 

I've attached an XML file for the UI Action record so you can just import it into your instance. As always, try it out in your company's development instance first, or better yet, your own personal development instance.