How do i add color and change font to "Check Box Text" in service catalog/portal?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2025 02:00 PM
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:)
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2025 09:02 AM
Hi @Bradley Bush ,
Here's a workaround to achieve this.
Add the following code in an onLoad Client Script, ensuring the UI Type is set to All.
function onLoad() {
//Type appropriate comment here, and begin script below
var url = top.document.location.pathname;
var append = "<span style='color:red;font-weight:bold'> (access should only be grated to cost center manager and above)</span>";
if (url == '/sp') {
//portal
setTimeout(function() {
var label = top.document.getElementById("label_drop_ship"); // usually renders the element id in the format label<<backened name of the variable>>
var text = label.innerHTML;
label.innerHTML = text + append;
}, 500);
} else {
//native
var checkBoxSysId='b00c36b8830c2210357c71a6feaad3bd'; // sysId of the checkbox
var attr='[for="ni.IO:'+checkBoxSysId+'"]'; //attribute of the label where the text is appended
var check = g_form.getControl('drop_ship'); //get the HTML element
var checkLabelID = check.parentElement; //targets the parent element of check box
var checkBoxLabel=checkLabelID.querySelector(attr); // get the text of label
var text = checkBoxLabel.innerHTML; // do modification to the label
checkBoxLabel.innerHTML = text + append; // reassign the modified label
}
}
I am using URL pathnames here to differentiate between native and portal, make sure you add your portal suffix in the code.
Screenshot from my PDI
Native
Portal
I noticed that getControl() for a checkbox does not return the actual checkbox added to the catalog form. Instead, we need to find the label element where the text is rendered using the object returned by getControl().
I hope this helps you achieve your requirement. 😊
Mark this as Helpful / Accept the Solution if this helps so that it helps future hunters.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2025 12:39 PM
hi Diveshnaik,
This really helped to get the code started, i noticed that it writes the text put in the code instead of recognizing the text already used for the variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2025 11:38 PM
Hi @Bradley Bush ,
I'm glad my script was helpful to you! Please make the following changes to update the variable text.
function onLoad() {
//Type appropriate comment here, and begin script below
var url = top.document.location.pathname;
var append = "<span style='color:red;font-weight:bold'> (access should only be grated to cost center manager and above)</span>";
if (url == '/sp') {
//portal
setTimeout(function() {
var label = top.document.getElementById("label_drop_ship"); // usually renders the element id in the format label<<backened name of the variable>>
var text = label.innerHTML;
var updatedText=text.replace("(access should only be grated to cost center manager and above)",append);
label.innerHTML = updatedText;
}, 500);
} else {
//native
var checkBoxSysId='b00c36b8830c2210357c71a6feaad3bd'; // sysId of the checkbox
var attr='[for="ni.IO:'+checkBoxSysId+'"]'; //attribute of the label where the text is appended
var check = g_form.getControl('drop_ship'); //get the HTML element
var checkLabelID = check.parentElement; //targets the parent element of check box
var checkBoxLabel=checkLabelID.querySelector(attr); // get the text of label
var text = checkBoxLabel.innerHTML; // do modification to the label
var updatedText=text.replace("(access should only be grated to cost center manager and above)",append); // replace existing content in the variable text with styled test
checkBoxLabel.innerHTML = updatedText; // reassign the modified label
}
}
Mark this as Helpful / Accept the Solution if this helps so that it helps future hunters.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2025 03:41 PM
Hi, Diveshnaik The onLoad works good thank you. can it be adjusted to an onChange so the text stays when the request is submitted?
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var url = top.document.location.pathname;
var append = '<span style="color:red; font-size:16px;font-weight: bold;">(budgeting access should only be grated to cost center manager and above)</span>'; // Changed double quotes to single quotes
if (url === '/sp') {
setTimeout(function () {
var label = top.document.getElementById("kha_budgeting");
if (label) {
label.innerHTML += append; // Simplified string concatenation
}
}, 5000);
} else {
var checkBoxSysId = '86b3870cdbf12a007fe2f12aaf9619f6';
var attr = '[for="ni.IO:' + checkBoxSysId + '"]';
var check = g_form.getControl('kha_budgeting');
if (check) { // Check if the control exists
var checkBoxLabel = check.parentElement.querySelector(attr);
if (checkBoxLabel) {
checkBoxLabel.innerHTML += append; // Simplified string concatenation
}
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2025 01:11 AM
Hi @Bradley Bush ,
The onChange script executes whenever there is a change in the variable value. Which variable would you like this script to trigger on?