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

@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

Hi @Ankur Bawiskar ,

Yes tried it, its working.

 

 

Hi @Ankur Bawiskar ,

 

After making UI action for sure button is showing only in native but when clicked on it its not performing any actions in native view.

@sanvi 

you might have to update the script as well to ensure there is no server side code

OR

if it contains server side code then you use gsftSubmit() to make it work client + server

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

Hi @Ankur Bawiskar ,

Tried adding below code... not sure if its right.

 

function assignOrder(){
gsftSubmit(null, g_form.getFormElement(), 'assign');
}
 
 
current.assigned_to = gs.getUserID();
 
if (current.assignment_group == '36ef97c11b9984102e13b9dcdd4bcb66') { 
if(current.state == '-16') { //Open
current.state = '-15'; //Work in progress
}
if(gs.hasRole('activeUser'))
answer=false;
current.update();
action.setRedirectURL(current);