Change UI action button color

farci
Mega Expert

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

1 ACCEPTED SOLUTION

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.


View solution in original post

25 REPLIES 25

where can i find the Button ID?

farci
Mega Expert

Hi,



This code seems to work when I am using JavaScript Editor but not when I am using On Load, Client Script unable to figure out what is the hindrance.


see the screenshot and code below



//Change the color of the 'Approve' button to green


    changeButtonColor('approve', '#00CC00');


    //Change the color of the 'Reject' button to red


    changeButtonColor('reject', '#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){}


}


find_real_file.png


You earliest response is much appreciated.



Regards,


Narmi


Try this, I added a 1 second delay in executing the code



function onLoad() {


  setTimeout(function(){


  //Change the color of the 'Approve' button to green


      changeButtonColor('approve', '#00CC00');


      //Change the color of the 'Reject' button to red


      changeButtonColor('reject', '#CC0000');


  }, 1000);


}


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){}


}


Hi Alex,



Thanks for your response, However, it does not seem to work when pasted in client script and loaded the form.



find_real_file.png



Again it works only when I use the JavaScript Executor. I am not sure what I am missing here.



find_real_file.png



Regards,


Narmi


can you check the error console? try adding an alert right under the onload function on line 2 to see if your client script is even firing