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

Community Alums
Not applicable

Hi @Amol Pawar ,

To achieve this functionality, you can create a UI Action that displays an alert message prompting the user to save the form, and if they confirm, it will save the form without enforcing mandatory field validation.

Here’s how to implement it:

 

  • Navigate to UI Actions
    Go to System Definition > UI Actions in the application navigator.

  • Create a New UI Action
    Add the following details to the new UI Action:

    • Table: Select the relevant table (e.g., incident or your desired table).
    • Action Name: Enter a unique name, such as save_ignore_mandatory.

Condition: Specify when this UI Action should be visible. For example:

javascript
current.state != 'Resolved'; // Visible if the incident is not resolved.
 
Use the following script:
 

 

function saveWithoutMandatoryCheck() {
    var userConfirmation = confirm("Do you want to save the details? Mandatory fields will be ignored.");
    if (userConfirmation) {
        // Proceed to save the record ignoring mandatory fields.
        var ga = new GlideAjax('GlideRecordAjax');
        ga.addParam('sysparm_name', 'saveIgnoreMandatory');
        ga.addParam('sysparm_table', current.getTableName());
        ga.addParam('sysparm_sys_id', current.sys_id);
        ga.getXMLAnswer(function(response) {
            var result = response.responseText;
            if (result === 'success') {
                g_form.save();
            } else {
                alert('Failed to save the form. Please try again.');
            }
        });
    }
}

 

 

Script Include (if server-side)

 

var GlideRecordAjax = Class.create();
GlideRecordAjax.prototype = {
    initialize: function() {},

    saveIgnoreMandatory: function(params) {
        var table = params.sysparm_table;
        var sysId = params.sysparm_sys_id;

        var gr = new GlideRecord(table);
        if (gr.get(sysId)) {
            gr.autoSysFields(false); // Prevent mandatory field validation
            gr.update();
            return 'success';
        }
        return 'failure';
    },

    type: 'GlideRecordAjax'
};

 

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Amol Pawar 

But why?

Why to allow users to save record even when mandatory fields are not filled in?

It's not a good user experience

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Because you make have a very long form and the user may not be able to fill the form at ONCE. So the user may have to save as DRAFT to come back later on to SUBMIT.

Because you make have a very long form and the user may not be able to fill the form at ONCE.