Save Button on form to ignore mandatory fields and save

Amol Pawar
Tera Guru

Hi everyone!

 

I need to create a Save button that will appear on a form and save the record even if some mandatory fields have yet to be filled. The button should ignore the required fields and save the form.

 

Or

 

I need to create an alert message which will ask the user to save the details. If we click on Ok or Save on that alert, it should save the details on the form ignoring empty mandatory fields if there are any.

 

Let me know if you have any thoughts on this!

Thanks in advance, 

Amol

12 REPLIES 12

Runjay Patel
Giga Sage

Hi @Amol Pawar ,

 

Use below code in your UI action (Save As Draft). You need to make ui action client callable.

 

var confirm = Confirm('Are you sure?');
if(confirm){
var fields = g_form.getEditableFields(); // Get all fields on the form
    fields.forEach(function (field) {
        g_form.setMandatory(field, false); // Make each field non-mandatory
    });

}

 

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

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

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

 

RAMANA MURTHY G
Mega Sage
Mega Sage

Hello @Amol Pawar ,

 

Try following UI Action script

 

RAMANAMURTHYG_0-1734930611431.png

 

 

function makeConfirmation() {
    var answer = confirm('Do you want to save form? This ignores mandatory fields! ');
    if (answer) {
        var fields = g_form.getMissingFields();
        for (var i = 0; i < fields.length; i++) {
            g_form.setMandatory(fields[i], false);
        }

		gsftSubmit(null,g_form.getFormElement(),'save_ignore_required');
    }
}

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

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

 

it is working fine for me, make changes according to your requirements

 

 

 

Please mark my answer helpful  & correct if it helps you
Thank you

G Ramana Murthy
ServiceNow Developer

Hi @RAMANA MURTHY G,

 

Thank you for your response first of all!

I tried with your solution but that button itself is not visible on the form. Let me know if I'm missing anything checking these snapshots:

AmolPawar_0-1735128171013.png

AmolPawar_1-1735128193594.png

Thanks in advance,

Amol

 

Hello @Amol Pawar ,

 

It looks like everything is fine, I can't find any mistake in it, the button should be visible on the form, make sure the Application scope is correct or not and try to change the order value and check. 

 

 

Please mark my answer helpful  & correct if it helps you
Thank you

G Ramana Murthy
ServiceNow Developer

It won't be visible on the portal side