Show/hide the submit button on catalog item form based on select box

Are Kaveri
Tera Contributor

Hi,

 

we have the below scenario for one of our client.

 

based on employee type we need to show submit button to submit the request on service portal.

 

 

for this I have written client script on onload. But not understanding how to achieve this

if(g_form.getValue(employee_type) == ‘full time’){
show submit button

}else {don’t show}

please help me with the scripting 

 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Are Kaveri 

are you sure Isolate script field is marked as False for your client script?

Share the latest script and what debugging have you done so far?

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

View solution in original post

10 REPLIES 10

Are Kaveri
Tera Contributor

@OlaN  that was the requirement that can't be changed . we have to hide submit button is there any solution to hide submit button?

 

Harish KM
Kilo Patron
Kilo Patron

Is this submit button on Portal page or native UI?

screenshot would be helpful

 

The below script will do

function onLoad() {
   //Type appropriate comment here, and begin script below
   var getEmployeeType = g_form.getValue('variabeName'); // check employee variable
   alert(getEmployeeType);
   if(getEmployeeType == 'alert value') // check alert value and pass here
   {
   if(window == null){
        // for portal
        var z = this.document.getElementsByClassName("btn btn-primary btn-block ng-binding ng-scope");
        z[0].style.display = 'none';
    }else{
        // for native
        document.getElementById("submit_button").style.display  = 'none';
    }
}
}
Regards
Harish

@Harish KM  for employee type full time also submit button was disappearing.

raja0077
Tera Expert

@re Kaveri

Hi,

 

you can use onSubmit catalog client script and stop the form submission.

 

function onSubmit() {
 
   if( g_user.employee_type=='full time'){
    return true;
  }else{
    alert("You are not a full time employee so you cant submit the reqest";
    return false;
  }
}
 
raja0077_0-1695623322600.png

Thanks

Ankur Bawiskar
Tera Patron
Tera Patron

@Are Kaveri 

are you sure Isolate script field is marked as False for your client script?

Share the latest script and what debugging have you done so far?

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