Prevent UI action modal from closing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2023 08:57 AM
I have a UI action with "Workspace Form Button" checkbox checked. In Workspace, I am able to click that button and enter data in a field. There two buttons: OK and Cancel. When hitting OK, I would like to do a field validation entered by a user. If the field has a certain value, I would like to throw an alert and prevent the modal from closing. Is this possible? Here is the code:
================================
function onClick(g_form) {
var fields = [{
type: 'string',
name: 'new_date',
label: getMessage('Enter new date:')
}
g_modal.showFields({
title: "Enter new date",
fields: fields,
size: 'md'
}).then(function(fieldValues){
if(fieldValues.updatedFields[0].value == '2023-05-19'){
alert("Today's date is not allowed. Please enter another date");
I would like to add something here that would prevent the modal from closing and stay on the modal form
}
else{
alert('Valid date has been entered');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-20-2023 10:53 PM
• Prevent the UI action modal from closing by using the "onBeforeClose" client script.
• The client script can be used to check whether the form is valid or not and prevent the modal from closing.
• The script can also be used to set a flag to indicate whether the form is valid or not.
• The flag can then be used to determine whether the modal should be closed or not.
• The onBeforeClose client script can also be used to execute a function before the modal is closed.
For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - https://nowgpt.ai/
For the ServiceNow Certified System Administrator exams try this :
https://www.udemy.com/course/servicenow-csa-admin-certification-exam-2023/?couponCode=NOW-DEVELOPER
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2024 03:11 AM
Hi @Mike114 ,
I have the same requirement. Would you able to achieve this?
Please let me know if it's possible to do validation & prevent modal to close.
Thanks & Regards,
Ankita
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2024 01:50 PM
Hello @Ankita Kolhe and @Mike114
Did you find the solution for this?