How do i add color and change font to "Check Box Text" in service catalog/portal?

Bradley Bush
Mega Sage

Hi, I need some help to get specific text to change color and size in a checkbox variable. In the example only the end of the text needs the modification "(access should only be granted to cost center manager and above)". I have tried a few examples and no luck. thank you:)

BradleyBush_0-1740607036731.png

 

function onLoad(){

	setTimeout(function(){ 
		
		if(window != null){
			// native
			g_form.getControl('kha_budgeting').setAttribute('style', 'font-weight: bold;color:red');
		}
		else{
			// portal
			var aTags = this.document.getElementsByClassName("ng-binding");
			var searchText = "access should only be granted to cost center manager and above"; // give the label name here
			var found;

			for (var i = 0; i < aTags.length; i++) {
				if (aTags[i].textContent.toString() == searchText) {
					aTags[i].style.fontWeight = 'bold';
					break;
				}
			}
		}

	}, 3000);

}

  

11 REPLIES 11

Hi,  Diveshnaik, I believe the onChange, because i need the adjustment to stay all the way through the processes, from REQ to SCTASK. If im wrong about that please let me know, thank you for your help.

Community Alums
Not applicable

Hi @Bradley Bush ,

 

The variable question only supports plain text with a default black color. Unfortunately, ServiceNow does not provide built-in styling options for variable questions, nor does it allow direct code or scripts within them.

 

After reviewing your code, I attempted to refine it and found a solution. However, this approach only applies the changes on the front end when the page loads and does not affect the backend. This means that once the catalog item is submitted, the changes will not persist.

 

You can still enable the "Applies on Requested Items" and "Applies on Catalog Tasks" options in the onLoad client script and modify the DOM accordingly. However, since ServiceNow uses different structures (DOM elements) for rendering pages, you will need to write separate code for each specific page you are targeting, such as Portal, Native UI, Requested Items, and SC Tasks.

 

I have another solution for you. You can make use of "Rich Text Label" variable below the checkbox and style it as per your need. This will work in the backend as well. 

image.png

 

 

You can do some thing like this:

Portal

image.png

 

Native UI

image.png

 

Req Item / SC Task

image.png

 

Mark this as Helpful / Accept the Solution if this helps so that it helps future hunters.