onSubmit

The onSubmit client script type runs when a form is saved. This type of script is not that widely used, as we can often use server-side script to perform actions for us once a record is saved, but it can be helpful, as it provides a final chance to execute client-side script before server-side script is run.

The script ServiceNow provides for onSubmit is quite similar to onLoad:

function onSubmit() {    //Type appropriate comment here, and begin script below}

The onSubmit script type can be used to check field values before a save takes place and abort the save if invalid values exist in fields. 

When considering writing an onSubmit script, it is worth thinking about whether that script could run on the server side instead. This is ...

Get Mastering ServiceNow Scripting now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.