How to disable the submit button in the catalog form if the variable choice option is Disagree

Sanjay E
Kilo Contributor

How to disable the submit button in the catalog form if the variable choice option is selected as Disagree

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Sanjay E 

Why not use onSubmit catalog client script and if the variable is Disagree stop form submission

function onSubmit(){

	if(g_form.getValue('variable') == 'Disagree'){
		alert('Not allowed');
		return false;
	}

}

you need to write onChange catalog client script on that variable

Show/hide the button using DOM

Note: DOM is not recommended approach

check this link for help

Show/Hide Submit button on Catalog Item

Regards
Ankur

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

View solution in original post

15 REPLIES 15

@Elena Pomana 

Can you please raise a new question for this as this is an older thread?

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

@Elena Pomana 

are you saying you don't want users from particular group to submit the request?

If yes then why not use User criteria with scripting and hide the catalog item itself if logged in user belongs to that group. then associate this user criteria for your catalog item

you are using asynchronous GlideAjax in onSubmit

So by the time the ajax function checks the form gets submitted as it won't wait as it's async

Here are couple of approaches

1) use onSubmit with synchronous GlideAjax; this is somewhat tricky and you need to check below links for solution and enhance as per your case

https://snprotips.com/blog/2018/10/19/synchronous-lite-onsubmit-catalogclient-scripts 

https://community.servicenow.com/community?id=community_question&sys_id=acb3103a1bd6c11038739979b04b... 

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

I have tried both ways, the form still gets submitted.

Here's the link to the new topic: https://www.servicenow.com/community/developer-forum/restrict-user-to-submit-form-via-onsubmit-clien...

Hi Elena,

 

Asynchronous call doesn't work on "OnSubmit" client script.
Please try and use "getXMLWait".

 

Thanks,

Soujanya.

Sanjay E
Kilo Contributor

Thanks all for your support.