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 11:16 PM
Hi,
In that case write a BR on HR Case table and use the script below:
BR Details:
Table Name: HR case
When: Before Update
Script:
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var gr = new GlideRecord('Child table');
gr.addQuery('parent', current.sys_id);
gr.addEncodedQuery('stateIN1,10,18');
gr.query();
if (gr.next()) {
gs.addErrorMessage('HR Task are still open');
current.setAbortAction(true);
}
})(current, previous);
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:25 PM
Sholke,
I tried this one solution and it is working for the action abort but not for the error message.
By this solution action is getting aborted but error message is not getting displayed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2022 11:36 PM
Error message will be displayed, have tested it and works fine it might be the message got displayed in some other page and not on your current page which happens in ServiceNow.
Do one thing Open a existing HR case in a new tab and then try doing it there might be a situation where the message is getting displayed in some other window of your which is an expected behavior.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2022 11:47 PM
I have done as per your suggestion but an error message is not displaying.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2022 11:56 PM
That is strange. Do as mentioned below:
1) Open a New Browser
2) Open HR Case in New Tab.
3) Now scroll down and now make sure that there is at least 1 HR Task in Open or Work in Progress state
4) Now try to move the HR case to Resolved or closed state and that should display you the message
Note if you are trying to add a new HR Task by clicking on the New button then in order to test this please make sure that you open the same HR Case in a new Tab and then try closing it.
Else what happens the message goes to a different screen and gets displayed.
Also can you check in other table on the same browser window if thta is getting displayed or not.
I have tested it again and works fine for me.
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke