Cancel tiket WO Task

yana7
Tera Contributor

I have a Cancel button but it only changes data for the user display, it should change for the server too,
as in the picture, when I select yes the status will be canceled but not saved, when I refresh or reload the form/browser the status is still work in progress
Please help me

yana7_0-1715761479606.png

 

This is the Code : 

function cancelTask() {
    // Prompt the user for the reason to cancel the task
    var reason = prompt("Apakah Anda yakin akan melanjutkan tindakan ini?\nMasukan alasan pembatalan:", "");

    // If the user enters a reason
    if (reason) {
        // Ask for confirmation with the entered reason
        var confirmation = confirm("Apakah Anda yakin akan membatalkan dengan alasan: " + reason);

        // If the user confirms
        if (confirmation) {
            // Update ticket fields
            g_form.setValue("state", 7);
            g_form.setValue("substate", '');
            g_form.setValue("work_notes", "Tiket Ini Cancel karena " + reason);
            g_form.update();

            // Execute server-side processing and handle success/failure
            gsftSubmit(null, g_form.getFormElement(), 'cancel_task');
            current.update();
            action.setRedirectURL(current);
        } else {
            // Handle cancellation
            alert("Pembatalan dibatalkan.");
        }
    }
}
2 REPLIES 2

Gangadhar Ravi
Giga Sage
Giga Sage

Please try below.

  function cancelTask() {
    // Prompt the user for the reason to cancel the task
    var reason = prompt("Apakah Anda yakin akan melanjutkan tindakan ini?\nMasukan alasan pembatalan:", "");

    // If the user enters a reason
    if (reason) {
        // Ask for confirmation with the entered reason
        var confirmation = confirm("Apakah Anda yakin akan membatalkan dengan alasan: " + reason);

        // If the user confirms
        if (confirmation) {
            // Update ticket fields
            g_form.setValue("state", 7);
            g_form.setValue("substate", '');
            g_form.setValue("work_notes", "Tiket Ini Cancel karena " + reason);

            // Execute server-side processing and handle success/failure
            gsftSubmit(null, g_form.getFormElement(), 'cancel_task');

            action.setRedirectURL(current);
        } else {
            // Handle cancellation
            alert("Pembatalan dibatalkan.");
        }
    }
}

if (typeof window == 'undefined')
    serverResolve();

function serverResolve() {
    current.incident_state = '7';
    current.state = '7';
    current.resolved_by = gs.getUserID();
    current.update();
}

 

 

 Please mark my answer correct and helpful if this works for you.

not Working bro