@CharanKulukuri 

I shared sample script.

it's obvious you need to enhance it as per your requirement.

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

iftekhar_mirza
Tera Guru

Hi @CharanKulukuri ,
Please refer to the following link. It may help you understand how to apply styles to fields in Service Portal.
Make a variable type Label bold on Service portal 
If you found this useful mark it as helpful
Regards,
Iftekhar

Rakesh_M
Mega Sage

Hello @CharanKulukuri ,
Modify and add these lines of code as per requirement

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
	var title=this.document.getElementById("sp_formfield_text");
	if(newValue=="1")
	{
		title.style.backgroundColor="blue";
	}
	else
	{
			title.style.backgroundColor="red";
	}
}

// here Element ID is "sp_formfield_+VariableName". 
//Prefix "sp_formfield_" is  concatenated
//if variable name is subnet_retrieved then element ID is "sp_formfield_subnet_retrieved"


As mentioned by @Ankur Bawiskar DOM manipulation can cause scripts to break or generate unexpected errors especially after platform upgrades.
 

View solution in original post

Hi @Rakesh_M ,

This kind of worked but the colour changed for field lable but not for value.
Screenshot 2026-04-08 162030.png

 

Is there a way I can change to for field value rather than field name?

 

Rakesh_M
Mega Sage

Hi @CharanKulukuri ,

Please inspect the page and identify the correct element ID for the input field, then update your script to target that element instead.