Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to hide button button on state change

ritaaudi
Tera Contributor

Hi: I want to be able to hide the Close Complete button on the RITM form when the state changes to Closed incomplete. I tried this but it didn't work:

ritaaudi_0-1712088041723.png

I don't get the alert 2 popup. Any idea? Thank you!

1 ACCEPTED SOLUTION

@ritaaudi If you dont mind, can you mark my response as correct where I suggested to create the UI action.


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

21 REPLIES 21

g k1
Tera Guru

in Ui Action only u can put condition in which state u want to show that field 

gk1_0-1712089518103.png


ex:

gk1_1-1712089594496.png

 

ritaaudi
Tera Contributor

Yes I can do that part, no problem but the script is not working:

if(g_form.getValue('state') == 4){
    alert("1");
    var items = $$('close_sc_task').each(function(item) {
       
            if (item.innerHTML.indexOf('Close Complete') > -1) {
                alert("2");
                item.hide();
            }
        });
 
 
It's erroring out on the "$$"

g k1
Tera Guru
Try this:-

if(g_form.getValue('state') == 4){
    alert("1");
    var items = $$('#close_sc_task').each(function(item) {
       
            if (item.innerHTML.indexOf('Close Complete') > -1) {
                alert("2");
                item.hide();
            }
        });
 

g k1
Tera Guru

also check whether close_sc_task is a Action name of your UI action

ritaaudi
Tera Contributor

Still gives me error: onChange script error: TypeError: $$ is not a function function () { [native code] }