Manadatory fields using client script

muskaanchan
Tera Contributor
function onChange(control, oldValue, newValue, isLoading) {
  if (isLoading) {
    return;
  }

  hideAll();

  // Approval Matrix
  if (newValue === "approval_matrix_modification") {
    g_form.setDisplay("name_of_approval_matrix", true);
    g_form.setDisplay("add", true);
    g_form.setDisplay("remove", true);
    g_form.setDisplay("details", true);
    // Visibility
  } else if (newValue === "visibility_modification") {
    g_form.setDisplay("name_of_item", true);
    g_form.setDisplay("add_visibility", true);
    g_form.setDisplay("remove_visibility", true);
    g_form.setDisplay("details_visibility_modification", true);

    // Form Modification
  } else if (newValue === "form_modification") {
    g_form.setDisplay("name_of_item_form", true);
    g_form.setDisplay("details_form_modification", true);
  }

  function hideAll() {
    g_form.setDisplay("name_of_approval_matrix", false);
    g_form.setDisplay("add", false);
    g_form.setDisplay("remove", false);
    g_form.setDisplay("details", false);

    g_form.setDisplay("name_of_item", false);
    g_form.setDisplay("add_visibility", false);
    g_form.setDisplay("remove_visibility", false);
    g_form.setDisplay("details_visibility_modification", false);

    g_form.setDisplay("name_of_item_form", false);
    g_form.setDisplay("details_form_modification", false);
  }
}
 
 
I want to make name of approval matrix and name of item mandatory. When I am using setMandatory function the form doesn't behave as expected. What should I do?
5 REPLIES 5

Hey @muskaanchan 

Hope you are doing well.

Did my previous reply answer your question?

If it was helpful, please mark it as correct ✓ and close the thread . This will help other readers find the solution more easily.

 

Thankyou & Regards

Vaishali Singh

Servicenow Developer
Linkedin - https://www.linkedin.com/in/vaishali-singh-2273361bb