Need to change color of variable on Service portal based on condition
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â10-21-2020 10:55 PM
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 .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â10-21-2020 11:48 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â10-22-2020 12:20 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â10-22-2020 11:11 PM
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';
}
}
Output:
How to get the HTML ID of your variable
1) inspect element
2) check like this
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
â10-25-2020 04:28 AM
Hello
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/?