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

fkhan
Kilo Guru

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


}



find_real_file.png


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";    


          }    


      }


}


find_real_file.png


Pradeep J
Kilo Guru

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.



Color.PNG





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


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";    


          }    


      }


}


find_real_file.png


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