Need help changing color on UI action buttons

Anthony16
Tera Guru

ServiceNow Version: London

I have added an approve and reject UI action button in the change_request form which work fine. However i would like to change the color of these buttons to green and red respectively. I have added the client script to try and do this based on my research. Can anyone tell me what I am missing or if its more involved than just those 2 things?

UI Action for approve:

find_real_file.png

Client Script for color change:

find_real_file.png

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

Hi,

If I'm understanding you correctly in that you just want to change the color of your UI Action button on the form...no client script in necessary. There's a field called "Form style" as seen in your screenshot and contains a few styles already OOB. One is "Destructive" which is red...so set your reject button to that style and that one is done.

For the Green version...you'd have to create that...please see this thread and specifically look for Chuck's response that gives details on how to add other colors: https://community.servicenow.com/community?id=community_question&sys_id=d2494725db5cdbc01dcaf3231f96...

Please mark reply as Helpful/Correct. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

5 REPLIES 5

Anurag Tripathi
Mega Patron
Mega Patron

Hii

 

They way i have done it in past is:

 

 On Line 3==>  changeButtonColor('<action name of button>', '<class Name>');  //class name can be success/danger etc.

 

Function on Line 8:

 

function changeButtonColor(buttonID, style) {
try{
$$('button[id=' + buttonID + ']').each(function(elmt) {
var jelmt = $j(elmt);
jelmt.removeClass('btn-default');
jelmt.addClass('btn-'+style);
});
}catch(e){}
}

 

-Anurag

-Anurag

I got this now:

 

function onLoad() {
//Change the color of the 'Approve' button to green
changeButtonColor('Approve', 'success');
//Change the color of the 'Reject' button to red
changeButtonColor('reject', '#FF0022');
}

function changeButtonColor(buttonID, style) {
try{
$$('button[id=' + buttonID + ']').each(function(elmt) {
var jelmt = $j(elmt);
jelmt.removeClass('btn-default');
jelmt.addClass('btn-'+style);
});
}catch(e){}
}

 

Still doesn't change color. Could there be something blocking it from changing color?

Try this

 

function onLoad() {
//Change the color of the 'Approve' button to green
changeButtonColor('approve', 'success');
//Change the color of the 'Reject' button to red
changeButtonColor('reject', 'danger');
}

function changeButtonColor(buttonID, style) {
try{
$$('button[id=' + buttonID + ']').each(function(elmt) {
var jelmt = $j(elmt);
jelmt.removeClass('btn-default');
jelmt.addClass('btn-'+style);
});
}catch(e){}
}

-Anurag

Allen Andreas
Administrator
Administrator

Hi,

If I'm understanding you correctly in that you just want to change the color of your UI Action button on the form...no client script in necessary. There's a field called "Form style" as seen in your screenshot and contains a few styles already OOB. One is "Destructive" which is red...so set your reject button to that style and that one is done.

For the Green version...you'd have to create that...please see this thread and specifically look for Chuck's response that gives details on how to add other colors: https://community.servicenow.com/community?id=community_question&sys_id=d2494725db5cdbc01dcaf3231f96...

Please mark reply as Helpful/Correct. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!