Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

Redirect to details tab when mandatory fields missing when clicking on save in SOW on change request

BotuM
Tera Contributor

Hello Everyone,

I have a requirement on the Change Request form in Service Operations Workspace.

When a user clicks the Save button after filling in only the fields available on the Overview tab, there may still be mandatory fields present on the Details tab that have not been completed.

The expected behavior is:

  • Prevent the record from being saved/submitted.
  • Automatically redirect the user to the Details tab.
  • Highlight the missing mandatory fields.
  • Display an appropriate validation message indicating that required fields must be completed before saving.

Has anyone implemented a similar requirement or can suggest the best approach to achieve this in Workspace?

Thanks in advance for your help.

BotuM_0-1788520217898.png

 

2 REPLIES 2

SVimes
Mega Sage

I'm assuming the fields are not literally configured to be mandatory which is why they can save the record without filling in those fields. I would be careful about doing that anyway.

 

What I'm guessing needs to be done is configure the change model. The model states can be configured such that going from one state to another is conditional. Automatic state transitions will happen once conditions are met so they won't set fields as mandatory, but manual state transitions allow you to make fields mandatory when the state is changed.

 

  1. Open the Change Model
  2. Open the Model State you want to manually transition from
  3. Open or create a State Transition
    • Ensure Automatic transition is false
  4. Open or create a Transition Condition
    • Ensure Requires is set to Mandatory Fields
  5. Create the Model State Transition Condition Fields to indicate which fields are mandatory before transitioning from one state to another
Sable Vimes - CSA | CAD | CIS-DF | CIS-ITSM

Alok Ranjan Das
Tera Guru

This can be achieved in Workspace with a combination of Workspace Client Scripts and form validation.

Steps:

  1. Create a Workspace Client Script (onSubmit) on the Change Request table.
  2. Validate the mandatory fields that reside on the Details tab.
  3. If any required field is empty:
    • Return false to prevent the save.
    • Display a form error message using g_form.addErrorMessage().
    • Programmatically switch the user to the Details tab.
    • Set focus to the first missing field using g_form.getControl() / Workspace APIs.
  4. The mandatory indicators will then be visible on the Details tab, guiding the user to complete the missing fields.
Pseudo logic:
function onSubmit() {
    if (!g_form.getValue('implementation_plan') ||
        !g_form.getValue('backout_plan')) {

        g_form.addErrorMessage(
            'Please complete all mandatory fields on the Details tab before saving.'
        );

        // Set focus to missing field
g_form.activateField('implementation_plan');

        return false;
    }
    return true;
}

 

Kindly mark my answer as Correct and helpful based on the Impact.
Thanks and Regards,
Alok