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.

Abort submission of catalog item

Tamas4
Kilo Contributor

Hello everyone,

I have a question regarding catalog item. I would like to abort the submission of a catalog item if a given field is not a number. I know it can be done in client script if I am not mistaken, but I don't know what should the code look like. 

if (isNaN(newValue) == true) is the first step, but I don't know what are the next steps in order to abort the submission. 

Thank you for your help in advance. 

1 ACCEPTED SOLUTION

Slava Savitsky
Giga Sage

You need to use an onSubmit client script and it needs to return false in order to abort the form submission. Try this:

if (isNaN(g_form.getValue('your_field_name')))
    return false;

View solution in original post

2 REPLIES 2

Slava Savitsky
Giga Sage

You need to use an onSubmit client script and it needs to return false in order to abort the form submission. Try this:

if (isNaN(g_form.getValue('your_field_name')))
    return false;

Fer Ortiz
Tera Contributor

Hello, you can try creating a client-side script from your catalog item form. You can do this by the context menu as shown below.

find_real_file.png

Then you click the New button and set type field to onSubmit. To avoid item to be send if a certain condition is not meet, you can try something like

if(!condition){//note that i am checking for false result
   g_form.addInfoMessage('A message to indicate the error');
   return false;
}

You can also use g_form.addErrorMessage() to set a message more clear.