Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How can i cancel submit in OnSubmit client script based on a asynchronous GlideAjax call

divya35
Kilo Explorer

Hi,

I have a requirement to cancel submit of a catalog item based on a asynchronous GlideAjax call. I am not able to return false from the response function. Previously it worked with a synchronous GlideAjax call as there was no function call.

Please advise.

Thanks in advance.

3 REPLIES 3

afnaim_michael
Giga Contributor

Hello Divya,



Can you share your script?  



You should be able to cancel the submission by returning false in the onSubmit function.  


Take a look at this wiki article - Client Scripts - ServiceNow Wiki



Kind Regards,



Michael




PS - Please mark Helpful, Like, or Correct Answer if applicable.


I believe the problem is making an AJAX call in onSubmit.   Ajax calls are async and Ajax Wait does not work in service portal which means it will make the call to Ajax and keep running even though you did not get your response back from ajax call to say false if it fails.   onSubmit will continue working and end things thinking all is good even though your ajax call is off getting you answers..     I was able to find a solution in my case but it is not ideal and I would love to know if someone knows a better way.   I had to move the call to an onChange event but I was never really happy with how I got it working.   Ajax Wait was a nice thing for this.....



But yes return FALSE in onSubmit will not allow it to continue.


VaranAwesomenow
Mega Sage

Dear Divya,



Is there is a reason why you are trying to use asynchronous ajax call?