Need to change color of variable on Service portal based on condition

sm88
Kilo Contributor

I need to change Color of variable of catalog item on service portal based on condition . I tried with g_form.getControl but it is not working in portal. Any help on script here will be highly appreciated .

Thank u in advance .

5 REPLIES 5

Viraj Hudlikar
Giga Sage

Hi sm88,

Check this LINK. Hope it might be helpful for you.

Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.

Thanks & Regards,
Viraj Hudlikar.



Thank You for your help but I am actually looking to change background color of variable and not to change color of label of variable. Any help on this part?

Ankur Bawiskar
Tera Patron
Tera Patron

@sm88 

g_form.getControl() won't work in portal.

You can change the background color of variable but that would require DOM manipulation which is not recommended.

If you still require then use onChange client script on the variable

Ensure Isolate Script field is set to false. This will ensure DOM runs

This field is not on form but form list you can make it false

Sample script below

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

// give the html element ID below

if(newValue == 'value1'){

// show red

document.getElementById('sys_display.IO:1354ac6b07335450540bf2508c1ed0d2').style.background = 'red';

}

if(newValue == 'value2'){

// show blue

document.getElementById('sys_display.IO:1354ac6b07335450540bf2508c1ed0d2').style.background = 'blue';

}

}

find_real_file.png

Output:

find_real_file.png

How to get the HTML ID of your variable

1) inspect element

2) check like this

find_real_file.png

Regards
Ankur

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

Hello @Ankur Bawiskar 

Thank You for your help but I am getting javascript error on portal when trying your script. Can you please check if its working on portal?

Also if you have any other solution/?