The CreatorCon Call for Content is officially open! Get started here.

How to confirm a confirm modal in client script in UI Builder

shanker1
Giga Guru

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!

7 REPLIES 7

Bhuvan
Mega Patron

@shanker1 

 

Follow below articles to create this,


https://www.servicenow.com/community/itsm-articles/client-side-and-server-side-code-in-one-ui-action...

 

https://www.servicenow.com/community/next-experience-articles/how-to-use-ui-actions-in-workspaces/ta...

If this helped to answer your query, please mark it helpful & accept the solution.

 

Thanks,

Bhuvan

 

Ankur Bawiskar
Tera Patron
Tera Patron

@shanker1 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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.

kaushal_snow
Mega Sage

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.

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/