Is there a way to hide the HTML field editor toolbar on just one form?

bnine
Kilo Contributor

I know that you can go into System Properties > UI Properties and edit the 'Configures the editing toolbar' sections to choose what show up, but it looks like this will affect other parts of the system instead of just the app I am working in.

We only want to remove it on one form for now. Right now I have this HTML field being populated with the contents of the KB article being attached to the ticket, and we are going to be sending the contents of the field to the caller in an email, and we want the user to be able to see what it will look like. (I had used the regex .replace() scripts floating around here remove the HTML tags that came up when the KB contents were copied into a regular string field in plain text, but that was inadequate). I think this is the

Is there a way to do this, maybe with a client script?

find_real_file.png

P.S. I have just over a month's worth of experience with ServiceNow, so let me know if I am posting this in the wrong place or something

1 ACCEPTED SOLUTION

ahaz86
Mega Guru

First thing that comes to mind is an on load client script.



function onLoad() {


  var sheet = window.document.styleSheets[0];


  sheet.insertRule('.mce-toolbar-grp { display: none !important; }', sheet.cssRules.length);


  sheet.addRule('.mce-toolbar-grp ', 'display: none !important;', -1); // IE likes to be different


}




Give that a shot


View solution in original post

25 REPLIES 25

ayman_h
Kilo Sage
Kilo Sage

Hi,

 

If you are experiencing this issue on an Order Guide or Catalogue Item, you can fix it by cloning the Order Guide or Catalogue Item widget and adding the CSS below

.mce-flow-layout {
display:none;
}

Thanks,
Ayman

 

xiaix
Tera Guru

I'm running on Kingston (patch 4), and have found a sure-fire way to remove the toolbar from an HTML field on Service Portal Service Catalog Items.

 

Create a widget.

Put this code into your widget:

Server Script:

(function() {
	// Get sysid's of form variables
	data.formVars = getFormVars($sp.getParameter('sys_id'));
})();

function getFormVars(v)
{
	var formVars = [];
	if (JSON.stringify(v) == "null")
		return formVars;
	var vars = new GlideRecord('item_option_new');
	vars.addQuery('cat_item', v);
	vars.addQuery('visible_summary', true);
	vars.addActiveQuery();
	vars.orderBy('order');
	vars.query();
	while (vars.next())
	{
		formVars.push({
			sysid:vars.sys_id.toString(),
			name:vars.name.toString(),
			question:vars.question_text.toString(),
			varType:vars.type.toString(),
			varTypeDV:vars.type.getDisplayValue().toString(),
			tblRef:vars.reference.getDisplayValue().toString(),
			mand:vars.mandatory.toString()
		});
	}
	return formVars;
}

 

Client Script:

function($scope, $timeout) {

	$scope.found = false;
	$scope.counter = 0;

	$scope.foundCheck = function()
	{
		/*
		   At this point, we know that there is an active HTML field on the form.
		   If $scope.initPage() didn't find it, this means the DOM hasn't fully loaded yet,
		   so we will re-call initPage()
		*/

		console.info("$scope.counter: " + $scope.counter);
		if (!$scope.found)
		{
			// Safety check to stop any infinite loop possibility.
			// Since we're calling the timeout every 100 milliseconds,
			// this will stop trying after 5 seconds.
			if ($scope.counter++ >= 50)
				return;
			else
				$scope.initPage();
		}
	};

	$scope.initPage = function()
	{
		var htmlFieldFound = false;
		var htmlField = "";
		var fv = $scope.data.formVars;

		// We only need to find 1 HTML field
		for (var i = 0; i < fv.length; i++)
		{
			if (fv[i].varTypeDV == "HTML")
			{
				htmlFieldFound = true;
				htmlField = fv[i].name;
				break;
			}
		}
		if (htmlFieldFound)
		{
			$timeout(function(){
				var divs = document.getElementsByTagName('div');
				for (var j = 0; j < divs.length; j++)
				{
					if (divs[j].className.indexOf('mce-toolbar') >= 0)
					{
						divs[j].style.display = "none";
						$scope.found = true;
					}
				}
				$scope.foundCheck();
			}, 100);
		}
	};

}

 

HTML:

<div ng-init="initPage()"></div>

 

Now, insert this widget into your Catalog Item as a variable:

find_real_file.png

Very helpful...  and now that i know you can call a widget from a macro, a new little world has opened up for me 🙂

Kimmo Toivonen
Tera Contributor

In Paris and later you can choose visible buttons by setting attribute "editor.toolbar" in dictionary, f ex below only full screen -button is shown:

find_real_file.png

result:
---


find_real_file.png

more info: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0957420


Well ain't that cool.  Thanks for noticing this and posting!