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

bhanu1189
Tera Contributor

Hi Kaveri 
I would suggest try to achieve this by using server side script as I think you don't have any value related to employee
because g_form is not going to access to user data
It would be better if you can attach your Catalog item snap to getter better idea

 

Thanks,

Bhanu

anshul_goyal
Kilo Sage

Hi @Are Kaveri,

Use the below method in the client script:
this.jQuery('button').hide();

Or, 
if a catalog item is just for informational purposes without any fields/values in it, I recommend you to create a Content Item instead of a Catalog item. Content Item does not contain these buttons and can be used in place of the catalog item.



Define a content item


I hope this will help you solve your problem. Please mark it as Accepted and Helpful.

Thanks and Regards,
Anshul

Hi @anshul_goyal 

it is a record producer.

 

my scenario is that 

for employee type = full time

allow submission

if employee type = part time

he was given a popup msg and submit button should be hidden.

i have written below script for hiding button.

But i want it based on employee type condition that i am unable to achieve using below script.

if(window == null){
		var z = this.document.getElementsByClassName("btn btn-primary btn-block ng-binding ng-scope");
		z[0].style.display = 'none';
	}else{
		document.getElementById("submit_button").style.display  = 'none';
	}

 

OlaN
Giga Sage
Giga Sage

Hi,

Not sure if hiding the submit button will be a good approach.

Might be better to highlight the form, or some variable to have the user make other selections.

Anyhow, a Catalog Client Script can prevent submitting the form if some specific conditions happen, like this:

 

function onSubmit() {
     if (some_condition_that_should_prevent_submit){
		g_form.addInfoMessage('You cannot submit because... some reason');
		return false;
   } 
}