How to make all fields readonly and mandatory in form using UI Policy?

akhileshv
Tera Contributor

I want to know whether there is any way to make multiple fields readonly together without using Client Script.

2 ACCEPTED SOLUTIONS

Danish Bhairag2
Tera Sage
Tera Sage

Hi @akhileshv ,

 

There is no other way apart from script(client) where u can add code to make all field read-only/mandatory.

Else UI policy which is sometimes pain.

 

Thanks,

Danish

 

View solution in original post

No, not possible to select more than one field, however you can try below code in UI policy script to see if it makes all fields read only based on condition , otherwise you have to settle for Client script. you can do this with ACL as well as that's the most preferred way of doing it.

 var fields = g_form.getEditableFields();
         for (var x = 0; x < fields.length; x++) {
           g_form.setReadOnly(fields[x], true);
}
Please hit like and mark my response as correct if that helps
Regards,
Musab

View solution in original post

6 REPLIES 6

Robbie
Kilo Patron
Kilo Patron

Hi @akhileshv,


If I understand your question correctly, you’re looking for an alternative to make fields read only without using a client script or UI Policy? (The title and description is a little confusing. Are we talking about just read only control, or both read only and mandatory?)

 

Essentially, you have 4 standardized ways of handling the control of fields.

(Note, there are additional ways that I won’t cover here)

 

As you’ve highlighted, UI policies are one of them. You can either script within the UI policy or leverage UI policy actions. These UI policy actions enable you to configure a field to be read-only and/or mandatory without scripting. This sounds like it may fit your needs.

 

Secondly, you have Client Scripts (separate from UI policies), which as the name suggests require scripting.

Best practice is to implement UI Policies over Client Scripts due to the call and execution order.

 

Next would be dictionary-level attributes. For each field, you can set whether it is read-only and/or mandatory.  
Please note this is at table level. It is important to understand table inheritance here and to leverage Dictionary Override.

 

Lastly, we have ACLs. For read-only and edit capability of a field, you can achieve this by implementing an ACL (Access Control) or a number of ACL's depending on what you're trying to achieve. 

ACL's are a best practice and more secure compared to UI policies or client scripts as they are executed server side, therefore integrations for example will adhere to these rules.

Check out the below links to help guide you through this.

 

To help others (or for one-to-one direct help), please mark this response as correct and helpful.

 

Thanks, 

Robbie 

 

https://www.servicenow.com/community/itsm-articles/access-control-list/ta-p/2305018

https://docs.servicenow.com/bundle/vancouver-platform-security/page/administer/contextual-security/t...

 

Kristen Ankeny
Kilo Sage

Do you mean dynamically depending on which fields are shown on a view? If so, I believe client script is the only way to achieve this. If not, then on a UI policy you would add the policy actions for all fields that are on the form. 

In policy actions can we select more than one filed name  at a time? 

You create a policy action under the ui policy for each field.