How to confirm a confirm modal in client script in UI Builder
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi,
Can anyone please on the below use case:-
I want to call a confirm modal in the on submit button of risk workspace.
The modal should have a Yes or No button
On click of Yes, the page should get submitted.
On No, I've to populate a message alert to the user.
I've configured the modal confirm. But I want this to be called from within the UI page client script, rather than at the event handler.
Please suggest
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Follow below articles to create this,
If this helped to answer your query, please mark it helpful & accept the solution.
Thanks,
Bhuvan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
is that a form UI action or declarative action?
share some screenshots how you configured
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi Ankur, In the submit button of risk workspace (main page), i want to popup a dialog with yes or no. I've to call the dialog from the "validate and submit modal" client script. If user selects yes, i should allow the user to submit. Otherwise show a alert message.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hi @shanker1 ,
Yes, you can trigger a confirmation modal from a client script in UI Builder (e.g. in a workspace form submit). The trick is using the g_modal.confirm() API in your onSubmit (or onClick) client script, returning false to block the submit until the user confirms, then proceeding.....
Sample code:
if (confirmed) {
return true;
}
// Show confirmation modal
g_modal.confirm(
"Confirmation",
"Are you sure you want to submit?",
function(userConfirmed) {
if (userConfirmed) {
confirmed = true;
g_form.submit();
} else {
g_form.addInfoMessage("Submission cancelled by user.");
}
Note: Use the correct action name if you're using a UI Action. If your submit button is actually a UI Action, the g_form.submit('action_name') version might be needed....
If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/