A
n important part of managing the flow of any record submission is to be able to validate the information from the form or record and provide feedback to the end-user if there is something that they need to change. While there are many ways to validate different kinds of data, preventing the submission of that data is pretty straight-forward. In Service-now, there are two different ways to stop the submission of a record. One method works client-side (in the rendered html form) and the other method works in server-side javascript as the record hits the database.
Client-side abort:
Preventing client-side form submission is very simple. All you need to do is set up an ‘onSubmit’ client script and return ‘false’ in the script. Of course, you won’t simply want to return false, you’ll want to actually validate something first. Here’s a simple example that aborts submission of the user tries to submit a high-priority incident.
if(g_form.getValue('priority') == 1){
alert('Record submission aborted.');
return false;
}
}

Server-side abort:
Server-side validation is also very simple. The primary difference with server-side validation is that it works in a business rule. Because of that, the syntax is slightly different. The most important part of this type of validation is that your business rule has a ‘When’ value of ‘Before’…so that your business rule runs before insert or update…otherwise the database action will have already taken place by the time your script runs.
Server-side aborts make use of the ‘setAbortAction’ method. SetAbortAction simply tells the system to abort the next database action (insert, update, or delete) for the record it is used against. Here’s an example script and screenshot of setAbortAction in a ‘Before’ business rule.
current.setAbortAction(true);
}

Whenever I use this method I always add another information message so it is clear to the user what happened.
gs.addInfoMessage('Record submission aborted.');
current.setAbortAction(true);
}
