How to abort the action performed by the user for onChange client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2022 10:50 PM
Hi,
I need to abort an action performed by the user by using onChnage client script.
Please could anyone help me to get it done.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2022 10:58 PM
Hi, Please refer to this thread https://community.servicenow.com/community?id=community_question&sys_id=03125721db101fc01dcaf3231f9619ed
Please Mark Correct And Helpful. Thanks!
Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2022 10:58 PM
Hi,
you can stop user from submission only using onSubmit
OR
you can use onChange client script and if validation fails then clear the field which you are validating and make it mandatory
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2022 11:10 PM
Hi Ankur,
Thank you for the response.
But scenario is when the HR case is created and assign to 'Assign to user', then the assign to user should not close the case by clicking on the 'Resolve Case' button until and unless the related HR tasts gets closed complete. So here as per requirement, expected is to display the error message that "HR tasks are not closed complete, first complete it". and at the same time the action performed by the assign to user (clicked on "Resolve Case" UI action) gets aborted.
I am able to display the error message by using onChange client script and script include, but the action is not getting aborted.(Once the assign to user clicks on Resolve Case UI action, case state is getting change to Resolved" even the HR tasks are not completed. Which should not get happened.
Could you please suggest me to achieve this requirement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2022 11:37 PM
mostly in such case we use before update BR and stop form submission
Before update on HR Case
Condition: State Changes to Resolved
Script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord("sn_hr_core_task");
gr.addActiveQuery();
gr.addQuery("parent", current.getUniqueValue());
gr.setLimit(1);
gr.query();
if (gr.hasNext()) {
gs.addErrorMessage("Not allowed to close as pending HR task");
current.setAbortAction(true);
}
})(current, previous);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader