Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Making section mandatory

Vanit
Mega Contributor

Hi,

I'm trying to make a section mandatory on form. Can anyone please provide any pointers.

Thanks.

4 REPLIES 4

amlanpal
Kilo Sage

Hi Vani,



Either you can make any field of the section Mandatory onLoad or you can check it onSubmit as bellow. Write a Client script onSubmit to check and show alert message.



if (g_form.getControl('field_1') && g_form.getControl('field_2') && g_form.getControl('field_3')){


  if(g_form.getValue('field_1') == '' || g_form.getValue('field_2') == '' || g_form.getValue('field_3') == ''){


  g_form.setMandatory('field_1', true);


  g_form.setMandatory('field_2', true);


  g_form.setMandatory('field_3', true);


  alert('Please complete the mandatory fields');


  return false;


  }


  }




I hope this helps.Please mark correct/helpful based on impact


anupama8
Tera Expert

I guess if you make fields under that section mandatory by Ui Policy, the section will itself become mandatory.



PS: Hit like, Helpful or Correct depending on the impact of the response.


Vanit
Mega Contributor

Hi,



We have many questions in the section, of which all are mandatory. Mandatory pop-up should display only the section name, but not the entire questions.



So, looking for the making section mandatory.



Thanks


Vani


Inactive_Us1883
Mega Expert

Hi Vani,



you can write a client script onSubmit to check and show message accordingly,



for example,



if(g_form.getValue('yourFieldName1') == '' || ..so on...)


{


      // give the section mandatory message


      alert('Section XXX mandatory, please fill the all fields etc...');


      return false;


}



If this is a catalog item form, then you can use catalog UI policies to control it too.


More details: Service Catalog UI Policy - ServiceNow Wiki



BR,


/Suraj