Workspace yes and no popup

Sandeep8987
Tera Contributor

Hi,

function onClick() {

    var comments = g_form.getValue("comments");
    if (!comments) {
        alert('The "Additional comments" field must be filled in before the transtitioning to Canceled');
        return false;
    }	
g_modal.confirm('Confirmation', 'Are you sure you want to cancel this incident?', {
    cancelTitle: 'No',    // Custom label for the 'No' button
    confirmTitle: 'Yes'   // Custom label for the 'Yes' button
}).then(function() {
    // Executes if user clicks Yes
   
    g_form.setValue('incident_state', '8'); // Cancelled
    g_form.setValue('state', '8');
    g_form.submitAction("cancel_incident"); // Trigger server-side UI Action
}, function() {
    // Executes if user clicks No or closes the dialog
 
});

I have written the workspace client script for yes and no button while clicking upon cancel ui action button.
The popup up is coming with yes and no but clicking on yes or no it is not working. 
Anupam 

 

1 ACCEPTED SOLUTION

Shruti
Giga Sage
Giga Sage

Hi @Sandeep8987 

Check this code

function onClick() {
    var comments = g_form.getValue("comments");

    if (!comments) {
        alert('The "Additional comments" field must be filled in before transitioning to Canceled');
        return false;
    }

    g_modal.confirm(
        'Confirmation',
        'Are you sure you want to cancel this incident?',
        function(confirmed) {
            if (confirmed) {
                g_form.setValue('state', '8');
                g_form.save();
            }
        }, {
            "cancelTitle": "No",
            "confirmTitle": "Yes"
        });

    return false;

}

  

View solution in original post

3 REPLIES 3

Shruti
Giga Sage
Giga Sage

Hi @Sandeep8987 

Check this code

function onClick() {
    var comments = g_form.getValue("comments");

    if (!comments) {
        alert('The "Additional comments" field must be filled in before transitioning to Canceled');
        return false;
    }

    g_modal.confirm(
        'Confirmation',
        'Are you sure you want to cancel this incident?',
        function(confirmed) {
            if (confirmed) {
                g_form.setValue('state', '8');
                g_form.save();
            }
        }, {
            "cancelTitle": "No",
            "confirmTitle": "Yes"
        });

    return false;

}

  

Thanks a lot @Shruti  , the code is working fine now.

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Sandeep8987 

try this

function onClick(g_form) {
    var comments = g_form.getValue("comments");
    if (!comments) {
        alert('The "Additional comments" field must be filled in before transitioning to Canceled');
        return false;
    }

    g_modal.confirm('Confirmation', 'Are you sure you want to cancel this incident?', {
        cancelTitle: 'No',
        confirmTitle: 'Yes'
    }).then(function() {
        // User clicked Yes
        g_form.setValue('incident_state', '8');
        g_form.setValue('state', '8');
        g_form.submitAction("cancel_incident");
    }, function() {
        // User clicked No or closed the dialog
        // Do nothing, just exit
    });
}

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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