- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-12-2016 05:30 AM
Hi,
I am struggling here to change the UI action button color to green when the button name is Approve and Red for button with name Reject.
Change the Color of Form Buttons - ServiceNow Guru
I also looked at the above link but to no avail.
You quickest response on this is appreciated.
Regards,
Narmi
Solved! Go to Solution.
- 14,597 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-14-2016 06:14 AM
You should be all set now. I went in and added a console.log statement inside of your "catch". This gave me the information that jquery was inaccessible, which in a scoped app it is not by default. (Scoped Applications and Client Scripts: A Primer )
I created a system property for you "x_69534_superduper.glide.script.block.client.globals" which enables this. (ServiceNow )
I disabled all of the alerts and the timeout that were set through testing and everything seems to work now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-12-2016 06:23 AM
You need to write acrtion name in client script which is defined on ui action.
function onLoad() {
//Change the color of the 'resolve' button to red
changeButtonColor('resolve_incident', '#ff0000');
//Change the color of the 'Approve' button to green
changeButtonColor('action_name of approve button', '#00CC00');
//Change the color of the 'Reject' button to red
changeButtonColor('action name of reject button', '#CC0000');
}
function changeButtonColor(buttonID, backgroundColor) {
try{
//Find the button(s) by ID and change the background color
$$('button[id=' + buttonID + ']').each(function(elmt) {
elmt.style.backgroundColor = backgroundColor;
elmt.style.color = '#ffffff'; //make the button text white
});
}catch(e){}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-13-2016 12:41 AM
Hi,
I tried all the options shared to me but it doesn't seem to work.
finally I tried the below code it works when I am using JavaScript Editor and not on Client script.
function onLoad() {
//Type appropriate comment here, and begin script below
alert('hi');
var outage = document.getElementsByTagName('button');
for(i=0;i<outage.length;i++)
{
if(outage[i].innerHTML.indexOf('Approve') > -1)
{
// alert("Button color");
outage[i].style.backgroundColor = "#00ff00";
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-12-2016 07:08 AM
Hi,
Following is the Client script onLoad:
use the UI Action sys_id if you have not mention the Action name in UI Action .
If you have used any name then you should use the same.
function onLoad() {
//Type appropriate comment here, and begin script below
//changeButtonColor('2a41b1a70fd6e2008483306be1050e53', '#338AFF'); use sys_id if Action Name is empty
changeButtonColor('up_emp', '#338AFF'); // use Action Name value from the UI Action
}
function changeButtonColor(buttonID, backgroundColor) {
try{
//Find the button(s) by ID and change the background color
$$('button[id=' + buttonID + ']').each(function(elmt) {
elmt.style.backgroundColor = backgroundColor;
elmt.style.color = '#ffffff'; //make the button text white
});
}catch(e){}
}
PS - Please mark Helpful, Like, or Correct Answer if applicabl
Thanks
Pradeep D J
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-13-2016 12:39 AM
Hi,
I tried all the options shared to me but it doesn't seem to work.
finally I tried the below code it works when I am using JavaScript Editor and not on Client script.
function onLoad() {
//Type appropriate comment here, and begin script below
alert('hi');
var outage = document.getElementsByTagName('button');
for(i=0;i<outage.length;i++)
{
if(outage[i].innerHTML.indexOf('Approve') > -1)
{
// alert("Button color");
outage[i].style.backgroundColor = "#00ff00";
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2016 04:51 AM
Hi Pradeep,
This script had finally worked for my requirement, However, If I make the UI Action button to 'List banner button' the color of button doesn't change. any thoughts?
Thank You for your support.
Regards,
Narmi