Cancel Case UI Action: Workflow

Amit83
Tera Contributor

Hi,

I am using the following script for UI action to cancel the case. This is working fine except one thing- despite setting the workflow to false, a notification is being sent. How can I stop notifications from being sent?

function confirmCancellation() {

    var confirmation = confirm('Are you sure you want to cancel this case?');

    if (confirmation) {
        g_form.setValue('state', '7');
        for (var i = 0; i < g_form.elements.length; i++) {
            var el = g_form.elements[i];
            var fieldName = el.fieldName;
            g_form.setMandatory(fieldName, false);
        }
        g_form.setMandatory('close_notes', true);
        gsftSubmit(null, g_form.getFormElement(), 'cancelCase');
        current.setWorkflow(false);
    }
}

if (typeof window == 'undefined') {
    cancelThisCase();
}

function cancelThisCase() {
    current.state = '7';
    current.setWorkflow(false);
    current.work_notes = 'Case cancelled by ' + gs.getUserName();
    current.update();
    action.setRedirectURL(current);
}

 

Please help me stopping the notification whenever this UI action is clicked.

Regards,

Amit

1 ACCEPTED SOLUTION

Amit Pandey
Kilo Sage

Hi 

 

Pls set onClick as confirmCancellation() and use the following script-

function confirmCancellation() {

    var gm = new GlideModal('convertToLabel');
    gm.setTitle('Reason For Cancelation');
    gm.renderWithContent('<div style="padding:15px"><p>Please write the reason for canceling this case.</p><p><textarea  id="taskCancellation" name= "cancellation" rows="2" cols="60"></textarea></p><div style="padding:5px;float:right"><button style="padding:5px;margin-right:10px" onclick="window.changeTaskAction(this.innerHTML,jQuery(\'#taskCancellation\').val())" class="btn btn-success">Don\'t Cancel</button><button  style="padding:5px" class="btn btn-danger" onclick="window.changeTaskAction(this.innerHTML,jQuery(\'#taskCancellation\').val())">Cancel Case</button></div></div>');

    window.changeTaskAction = function(thisButton, thisAction) {
        gm.destroy();
        if (thisButton == 'Cancel Case') {
            var userInput = thisAction;
            if (thisAction) {
                g_form.setValue('state', '7');
                g_form.setValue('close_notes', thisAction);
                g_form.setValue('active', 'false');

                var fields = g_form.getEditableFields();
                for (var x = 0; x < fields.length; x++) {
                    g_form.setMandatory(fields[x], false);
                }
            }
            gsftSubmit(null, g_form.getFormElement(), 'cancelCase');
        }
    };
    return false; //prevents the form from submitting when the dialog first loads
}
if (typeof window == 'undefined') {
    cancelThisCase();
}

function cancelThisCase() {
    current.state = '7';
    //current.active = 'false';
    current.closed_at = new GlideDateTime();
    current.setWorkflow(false);
    current.work_notes = 'Case cancelled by ' + gs.getUserName();
    current.update();
    action.setRedirectURL(current);

View solution in original post

10 REPLIES 10

Did you try this same code?

function confirmCancellation() {

    var confirmation = confirm('Are you sure you want to cancel this case?');

    if (confirmation) {
        g_form.setValue('state', '7');
        for (var i = 0; i < g_form.elements.length; i++) {
            var el = g_form.elements[i];
            var fieldName = el.fieldName;
            g_form.setMandatory(fieldName, false);
        }
        g_form.setMandatory('close_notes', true);
        gsftSubmit(null, g_form.getFormElement(), 'cancelCase');
       // current.setWorkflow(false);
    }
}

if (typeof window == 'undefined') {
    cancelThisCase();
}

function cancelThisCase() {
    current.state = '7';
    current.setWorkflow(false);
    current.work_notes = 'Case cancelled by ' + gs.getUserName();
  current.setWorkflow(false);
    current.update();
    action.setRedirectURL(current);
}

Hi Sumanth,

Yes, I tried with the same code. 

It only works when I comment out this line-

 g_form.setMandatory('close_notes', true);

But with this, the notification is sent.

Regards,

Amit

//Client-side 'onclick' function

function confirmCancellation() {

    if (g_form.getValue('close_notes') == '') {
        g_form.hideFieldMsg('close_notes');
        g_form.setMandatory('close_notes', true);
        return false; //Abort submission
    }

    gsftSubmit(null, g_form.getFormElement(), 'cancelCase'); //MUST call the 'Action name' set in this UI Action

}

//Code that runs without 'onclick'

if (typeof window == 'undefined'){

    serverCancel(); }

function serverCancel() {

    current.state = '7';
    current.setWorkflow(false);
    current.work_notes = 'Case cancelled by ' + gs.getUserName();
  current.setWorkflow(false);
    current.update();
    action.setRedirectURL(current);


}

 

Can you try this

Hi Sumanth,

 

Now nothing is happening when I am clicking on Cancel Case UI action. 

 

Regards,

Amit

I removed the confirm box.

If the close_notes is not filled then it will just make the field mandatory.