UI action displays a dialog box with 'Yes' and 'No' buttons

SauravR58560934
Tera Contributor

I need to create an onSubmit client script that displays a dialog box with 'Yes' and 'No' buttons instead of the default 'Cancel' and 'OK'. If the user selects 'Yes', the state should change to 'Closed'. If the user selects 'No', the state should remain unchanged."

5 REPLIES 5

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @SauravR58560934 

 

https://www.servicenow.com/community/incident-management-forum/how-to-show-a-pop-up-with-yes-or-no-r...

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Ajay_Chavan
Kilo Sage
onSubmit Client Script with Custom Yes/No Dialog
// Table: [Your Table]
// Type: onSubmit

function onSubmit() {
    // Prevent form submission initially
    return false;
}

function onLoad() {
    // Add this to onLoad to handle the dialog
    g_form.addButton('close_ticket', 'Close Ticket', function() {
        
        var dialog = new GlideModal('glide_confirm_standard');
        dialog.setTitle('Confirm Action');
        dialog.setBody('Are you sure you want to close this ticket?');
        
        // Custom Yes/No buttons
        dialog.addButton('Yes', function() {
            g_form.setValue('state', 'closed'); // Set to closed state value
            g_form.save();
            dialog.destroy();
        });
        
        dialog.addButton('No', function() {
            dialog.destroy(); // Just close dialog, no state change
        });
        
        dialog.render();
    });
}

Alternative: Simple Confirm Approach
// Type: onSubmit
function onSubmit() {
    if (confirm('Do you want to close this ticket?')) {
        g_form.setValue('state', 'closed');
        return true; // Submit form
    }
    return false; // Cancel submission
}

Recommendation: Use the simple confirm approach for quick implementation - it's more reliable and precise.

Glad I could help! If this solved your issue, please mark it as ✅ Helpful and ✅ Accept as Solution so others can benefit too.*****Chavan A.P. | Technical Architect | Certified Professional*****

If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Glad I could help! If this solved your issue, please mark it as ✅ Helpful and ✅ Accept as Solution so others can benefit too.*****Chavan A.P. | Technical Architect | Certified Professional*****