Avoid Mandatory Validation on click of UI Action

pavan_yakkala
Kilo Contributor

Hi,

I have a form on user defined table (u_ba_service_package) and created 2 UI Actions "Save" and "Cancel".

I have   mandatory fields on the form and on click of "Save" and "Cancel" mandatory fields are validating and getting an alert "The following mandatory fields are not filled in:<field 1>,<field 2> etc.."

but i don't want to validate mandatory fields on Click of "Cancel". it should be happened only when click of "Save".

How can i achieve this? can any one please help me on this?

Thanks,

Pavan.

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee
6 REPLIES 6

pawan k singh
Tera Guru

You can try below code on UI action. It will work.

function callClientScript() {
    //Client Script
    var arr = g_form.getMissingFields();
    for (var x = 0; x < arr.length; x++) {
        g_form.setMandatory(arr[x], false);
        alert("Following fields are set Non Mandatory: " + arr[x]);
    }
    gsftSubmit(null, g_form.getFormElement(), 'update_to_p1'); // UI action name
}

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

function serverScript() {
    // Server Script
    current.update();
    action.setRedirectURL(current);
}

find_real_file.png

Please mark answer helpful if it helped.
Regards
Pawan K Singh

elphilli
Tera Contributor

I have the same requirement but mine isn't working as expected. I have two variables I have made mandatory via UI Policy/Action on sctask. However, when the state of the sctask is marked Closed Incomplete, I need the two variables no longer be mandatory once the UI Action button "Update" has been selected. 

 

Here's my script in the UI Action "Update":

 

function checkMandatoryFields() {
    var state = g_form.getValue('state');
    if (state == 4) {
        g_form.checkMandatory = false;
    }
}
current.update();