- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
I want to change the background color of single line text field for a catalog item on ServicePortal when user is trying to submit a form.
Basically it should work on an onChange of other field. the field I want to change is just a single line text and Presetted value in it. it will be visible based on the other field.
I tried Isolated script true and false and also tried g_form.setStyle and getControl nothing worked.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
on portal you can use DOM but DOM is not recommended
see this link and enhance it further
How to make text of Label type in Bold
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
Hi Ankur,
My field is not a label type it is single line text field I am using it dynamically based on other fields.
User will select any value from choice field - Subnet
once it is selected we run a flow via script and It will take sometime to run and give the ouputs.
Once subnet is selected I gave a string in single line text field
So based on the script and configuration I want that change accordingly.
script:
So I dont want to use label. as I should create 4 fields If i go with label
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
I shared sample script.
it's obvious you need to enhance it as per your requirement.
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
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
