- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2024 08:41 AM
Hello,
Can anyone please explain which is better among onSubmit client script and Before business rule (current.setAbortAction(true)) to perform relevant validations? Also please explain with example, which one among these suits better in what kind of scenarios.
Thanks in advance,
Suchitra
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2024 08:56 AM
Hi @SuchitraM ,
Go through this comparison below.
The choice between an onSubmit client script and a Before business rule with current.setAbortAction(true) for performing validations in ServiceNow depends on various factors, including performance, user experience, and the nature of the validation.
OnSubmit Client Script
Definition: Client scripts run on the client-side (browser) and can validate data before it is sent to the server.
Advantages:
- User Experience: Immediate feedback to the user without a server round-trip.
- Performance: Reduces load on the server as validations are done on the client-side.
- Ease of Use: Simple to implement for basic form validations.
Use Case:
- Simple Validations: Required fields, format checks, and basic conditional logic.
- Immediate Feedback: Scenarios where user experience is a priority, and you want to provide instant feedback.
Before Business Rule with current.setAbortAction(true)
Definition: Business rules run on the server-side and can perform complex validations and actions before the database is updated.
Advantages:
- Complex Validations: Can perform more complex logic, including querying the database.
- Security: Validations are enforced on the server-side, ensuring data integrity regardless of client-side behavior.
- Auditability: Server-side logging and auditing capabilities are enhanced.
Use Case:
- Complex Business Logic: Scenarios requiring database queries, complex conditions, or integrations with other systems.
- Data Integrity: Ensuring validations are enforced regardless of client-side modifications or bypasses.
- Security: Validations that are critical for security or compliance reasons.
Comparison and Scenarios
Performance and User Experience:
- OnSubmit Client Script: Better for user experience and immediate feedback without server load.
- Before Business Rule: Better for scenarios where server-side validation is crucial for data integrity and security.
Complexity of Validation:
- OnSubmit Client Script: Suitable for simple validations that do not require server resources.
- Before Business Rule: Suitable for complex validations involving database queries or other server-side logic.
Security and Data Integrity:
- OnSubmit Client Script: Can be bypassed if users disable JavaScript in their browser or manipulate the client-side code.
- Before Business Rule: Ensures validations are always enforced on the server, providing better security and integrity.
Thanks.
Hope this helps.
If my response turns useful, please mark it helpful and accept answer.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2024 08:59 AM
@SuchitraM Validations using an onSubmit script will always be preferred over a business rule, as you can validate the inputs at the browser level without making a server hit. However, users can disable client script from running at the browser, in such a case it will always be better to have a Data policy in place to maintain the data consistency.
Regarding current.setAbortAction(true); you can have it in a before business rule as a fallback of client script to prevent incorrect data entering in the table if client scripts are deactivated at the browser level.
Among two, clients scripts are always better for validations, as they save a server trip.
Please mark the response helpful and accepted solution if it addresses your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2024 08:56 AM
Hi @SuchitraM ,
Go through this comparison below.
The choice between an onSubmit client script and a Before business rule with current.setAbortAction(true) for performing validations in ServiceNow depends on various factors, including performance, user experience, and the nature of the validation.
OnSubmit Client Script
Definition: Client scripts run on the client-side (browser) and can validate data before it is sent to the server.
Advantages:
- User Experience: Immediate feedback to the user without a server round-trip.
- Performance: Reduces load on the server as validations are done on the client-side.
- Ease of Use: Simple to implement for basic form validations.
Use Case:
- Simple Validations: Required fields, format checks, and basic conditional logic.
- Immediate Feedback: Scenarios where user experience is a priority, and you want to provide instant feedback.
Before Business Rule with current.setAbortAction(true)
Definition: Business rules run on the server-side and can perform complex validations and actions before the database is updated.
Advantages:
- Complex Validations: Can perform more complex logic, including querying the database.
- Security: Validations are enforced on the server-side, ensuring data integrity regardless of client-side behavior.
- Auditability: Server-side logging and auditing capabilities are enhanced.
Use Case:
- Complex Business Logic: Scenarios requiring database queries, complex conditions, or integrations with other systems.
- Data Integrity: Ensuring validations are enforced regardless of client-side modifications or bypasses.
- Security: Validations that are critical for security or compliance reasons.
Comparison and Scenarios
Performance and User Experience:
- OnSubmit Client Script: Better for user experience and immediate feedback without server load.
- Before Business Rule: Better for scenarios where server-side validation is crucial for data integrity and security.
Complexity of Validation:
- OnSubmit Client Script: Suitable for simple validations that do not require server resources.
- Before Business Rule: Suitable for complex validations involving database queries or other server-side logic.
Security and Data Integrity:
- OnSubmit Client Script: Can be bypassed if users disable JavaScript in their browser or manipulate the client-side code.
- Before Business Rule: Ensures validations are always enforced on the server, providing better security and integrity.
Thanks.
Hope this helps.
If my response turns useful, please mark it helpful and accept answer.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2024 08:59 AM
@SuchitraM Validations using an onSubmit script will always be preferred over a business rule, as you can validate the inputs at the browser level without making a server hit. However, users can disable client script from running at the browser, in such a case it will always be better to have a Data policy in place to maintain the data consistency.
Regarding current.setAbortAction(true); you can have it in a before business rule as a fallback of client script to prevent incorrect data entering in the table if client scripts are deactivated at the browser level.
Among two, clients scripts are always better for validations, as they save a server trip.
Please mark the response helpful and accepted solution if it addresses your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2024 04:56 AM