How to set up a Cancel Button with Confirm Dialog and skipping mandatory check?

Ratan B
Tera Contributor

Hi All,

We have the following requirement

  1. Cancel Button should prompt a Confirm Window (client-code)
  2. If Cancel Button is clicked, mandatory field check shall be skipped

I've return below code in UI action, but the problem is, that it seems like you can not combine sysverb_cancel with a client & server-side UI Action. This is what I observed:

  • Confirm dialog pops up correctly.
  • No error about missing mandatory fields is displayed
  • But the server side code is not triggered, it is not moving the record to cancelled state.

Code : 

function cancelTask() {
    var confirmBox = confirm('Are you sure to proceed with cancelling the task?');
    if (confirmBox) {
        gsftSubmit(null, g_form.getFormElement(), 'sysverb_cancel'); //MUST call the 'Action name' set in this UI Action
    } else {
        return;
    }
}

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

function cancel() {
    current.status = 'cancelled';
    current.update();
    action.setRedirectURL(current);
}

 

1 ACCEPTED SOLUTION

SANDEEP28
Mega Sage

@Ratan B You can achieve this requirement without using server side code also. Put below client side code in script section.

 

This I have tested for incident record and working fine. Put your "cancelled " state value in below statement. For incident record cancelled status value is 8.

g_form.setValue("state", "8");

 

function cancelTask() {
    var confirmBox = confirm('Are you sure to proceed with cancelling the task?');
    if (confirmBox) {
        var arr = g_form.getMissingFields();
        for (var x = 0; x < arr.length; x++) {
            g_form.setMandatory(arr[x], false);
		}
            g_form.setValue("state", "8"); //check the cancelled status value and put it here. 
            g_form.save();
        } else {
            return;
        }
    }

 

SANDEEP28_0-1692253423356.png

 

If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !! 

 

View solution in original post

7 REPLIES 7

SANDEEP28
Mega Sage

@Ratan B This UI action is on which table ? Do you want to skip mandatory fields and process record cancellation after click on Cancel UI action?

Ratan B
Tera Contributor

Hi Sandeep,
Yes, want to skip mandatory fields and process record cancellation after click on Cancel UI action.
The table is Custom Table and it is in Scoped Application.

SANDEEP28
Mega Sage

@Ratan B You can achieve this requirement without using server side code also. Put below client side code in script section.

 

This I have tested for incident record and working fine. Put your "cancelled " state value in below statement. For incident record cancelled status value is 8.

g_form.setValue("state", "8");

 

function cancelTask() {
    var confirmBox = confirm('Are you sure to proceed with cancelling the task?');
    if (confirmBox) {
        var arr = g_form.getMissingFields();
        for (var x = 0; x < arr.length; x++) {
            g_form.setMandatory(arr[x], false);
		}
            g_form.setValue("state", "8"); //check the cancelled status value and put it here. 
            g_form.save();
        } else {
            return;
        }
    }

 

SANDEEP28_0-1692253423356.png

 

If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !! 

 

SANDEEP28
Mega Sage

@Ratan B If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct !!