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-22-2022 12:10 AM
Ankur, i tired this solution but it is not working for error message display.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2022 12:23 AM
should show the error message irrespective of whether it's global or scoped app
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-22-2022 12:26 AM
if that doesn't work then you can use onSubmit with GlideAjax
But you need to have workaround so that Ajax waits for the script include function
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
If you want to do it using an On Change Client Script then you need to clear that field and make that field as Mandatory and that will make sure the user is not able to submit the form and will solve your purpose as well.
Sample script shared below where I am clearing out the field and making it mandatory as well:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if(newValue){
//Add your condition which you want to check
g_form.clearValue('Field Name'); // Replace "Field Name" with your Field here
g_form.setMandatory('Field Name',true); // Replace "Field Name" with your Field here
}
//Type appropriate comment here, and begin script below
}
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2022 11:12 PM
Hi Shloke,
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.