UI Policy - set all fields to Mandatory & Visible

hongsok
Tera Contributor

Hello all,

I create a UI policy to make all field ServiceNow Instance visible and mandatory only if the Change Category is ServiceNow

The question is: how can I select all fields instead of do it one by one?

3 REPLIES 3

sachin_namjoshi
Kilo Patron
Kilo Patron

As best practice, you should use UI policy to make field mandatory.

But you can use the getEditableFields call in a client script to make everything mandatory. This will only be effective when viewing the form, as all client side scripts are.

 

function onLoad(){

 

      var fields = g_form.getEditableFields();

 

      for(i=0; i<fields.length; i++){

 

              g_form.setMandatory(fields[i],true);

 

      }

 

}

 

Regards,

Sachin

hongsok
Tera Contributor

Yes, I did use UI Policy and there are a lot fields in the form. So I need to add it one by one?

 

If you don't want to do it using UI policy, then you can configure onload client script and use my below code in client script to make all fields mandatory.

You don't have to specify each field in client script.

 

Regards,

Sachin

function onLoad(){


 

      var fields = g_form.getEditableFields();


 

      for(i=0; i<fields.length; i++){


 

              g_form.setMandatory(fields[i],true);


 

      }


 

}

 

Regards,

sachin