Made all mandatory fields not required on click of OOTB "cancel change" ui action.

ilam334
Tera Expert

Made all mandatory fields not required on click of OOTB "cancel change" ui action but on cancel of  the dialog the fields are left not mandatory.

The fields should be back to mandatory or reload the form(which will make the form as previous).

ui action:

var changeConfirmCancelDialog;

function setChangeCancelState() {
    var fields = g_form.getMissingFields();
    if (fields.length > 0) {
        for (var i = 0; i < fields.length; i++) {
            g_form.setMandatory(fields[i], false);
        }
    }
    g_form.setValue("state", "4");
}

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


function setRedirect() {
    current.update();
    action.setRedirectURL(current);
}
 
Thanks in advance..
3 REPLIES 3

jMarshal
Mega Sage
Mega Sage

Just to be clear...are you wanting your fulfillers/technicians to populate mandatory fields before the cancel UI action will commit the cancel action and make the ticket inactive?

Don't want anyone to update the mandatory fields, just want to bypass any validation on mandatory fields on the form while canceling the CR.

for that purpose , i have added the below code to ootb 'cancel change' ui action

   var fields = g_form.getMissingFields();
    if (fields.length > 0) {
        for (var i = 0; i < fields.length; i++) {
            g_form.setMandatory(fields[i], false);
        }
    }
But if the someone don't want to cancel the change after the dialog is shown then we will click on 'cancel' button on the dialog but the fields which are marked as not mandatory to revert to mandatory or refresh the form(which will make the form as previous with all required fields)

Makes sense, you probably just have to embed your code in the right spot. Try putting it in the "setChangeCancelState" function:

var changeConfirmCancelDialog;

 

function setChangeCancelState() {
    
var fields = g_form.getMissingFields();
    if (fields.length > 0) {
        for (var i = 0; i < fields.length; i++) {
            g_form.setMandatory(fields[i], false);
        }
    }
 
g_form.setValue("state", "4");
 
}

 

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

 

function setRedirect() {
    current.update();
    action.setRedirectURL(current);
}


---------------------------------------

---------------------------------------


...however, know that when I'm testing on my PDI, it seems like the OOB action doesn't require mandatory fields, when you use the Cancel Change UI Action...it will "complain" (throw an "error message") about the mandatory field(s)...but it still sets the state to Cancelled (4) and saves the record as active=false.