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 because the client script runs in front of the user, and further processing must wait until the script finishes, whereas on the server side, the code is executed away from the user and can be executed alongside other scripts.

If you want to abort the form being submitted, return false from the onSubmit function.

We can see an onSubmit example in Figure 3.3:

Figure 3.3: Sample onSubmit client script

For our onSubmit client script example, we can see that this client script is ready for the script to be added for the change table.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.131.72