Hide Custom Button on the Portal

sanvi
Tera Expert

Hi All,

I want to hide a button called 'Assign' on the portal but it should display as is on the backend view i.e is native view.

Tried the below script (on load client script) but its not working.

 
setTimeout(function() {
 
                    disableButtons();
}, 1000);
 
function disableButtons() {
if(g_form.getValue('state') == '-15' || g_form.getValue('state') == '-16'){
    var btn = this.document.getElementsByClassName("btn btn-default m-r-xs");
 
    for (i = 0; i < btn.length; i++) {
        if (btn[i].innerText == 'assign') {
 
            btn[i].style.display = 'None';
 
                    }
}
 }
}
 
Can anyone suggest.
1 ACCEPTED SOLUTION

@sanvi 

why not make that UI action as client side and then it will only show in native and not in portal?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

10 REPLIES 10

Ankur Bawiskar
Tera Patron
Tera Patron

@sanvi 

in your client script ensure UI Type - ALL and Isolate Script field = false

did you add alert and see in your for loop?

You can also try to use UI action condition and check in url if it's a portal page; for my example I used sp

gs.action.getGlideURI().indexOf('sp') == -1

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar ,

in your client script ensure UI Type - ALL and Isolate Script field = false --- yes i have already set these

Yes i have added alert, i am not getting the alert message that i have added in 'for' loop.

Before that i am getting the alert.

 

Can you help.

 

@sanvi 

so it means it's not finding the html element

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar ,

Yes.... any other ways to achieve this? or make it work?