Ignore mandatory fields

Sometimes you want to test a particular feature in a long form with a lot of mandatory fields that are not relevant.

Filling them all every time you want to create or update a record can be very time-consuming.

Or you just want to change the view and Servicenow asks you to fill the mandatory fields, but you just want to change the view, not the data.

If the fields are only validated on client side (UI Policies, Client scripts), there is a quick way to skip this process.

Just run this in the developer console:

g_form.checkMandatory = false

Alternatives

  • Use /um in SN Utils. The code it triggers is a bit different. It removes the mandatory checks instead of ignoring them.
function snuSetAllMandatoryFieldsToFalse() {
    if (typeof g_form != 'undefined' && typeof g_user != 'undefined') {
        if (g_user.hasRole('admin')) {
            var fields = g_form.getEditableFields();
            for (var x = 0; x < fields.length; x++) {
                g_form.setMandatory(fields[x], false);
            }
            snuShowAlert('Removed mandatory restriction from all fields.', 'success');
        } else {
            snuShowAlert('Admin rights required.', 'danger');
        }
    }
}
  • Use /rnd in SN Utils to autopopulate if you don’t mind inserting random data.

Creating a bookmark

I like to have a bookmark in my browser so that I can skip the mandatory fields with just one click.

This example is for Chrome, but you should have similar options in other browsers.

Create a bookmark with the following URL:

javascript:g_form.checkMandatory = false
Code language: JavaScript (javascript)

Some considerations

  1. Validations on client side are great to help and guide your users to perform their tasks, providing feedback on the spot.
  2. But you cannot control what users do in their browser.
  3. Don’t rely on client side validations as security.
  4. Perform the important checks on the server.