Need to make all the fields read only on a form using UI policy

Abhilasha G T
Tera Contributor

Hi Team,

 

I Need to make all the fields an interaction form read only when the state is closed for SOW view.

am trying to do in UI policy, instead of adding all the 12 fields in UI Policy action, i need a script to write in the run script and to achieve.

 

 

regards,

Abhilasha G T

 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Abhilasha G T 

create a table.None WRITE ACL and add condition as State [IS NOT] Closed -> Easiest approach

OR

try this and create onload client script and uncheck Global checkbox and add the correct view name so that this script runs only for that view

function onLoad() {
    if (g_form.getValue('state') == 'closed') {
        var fields = g_form.getEditableFields();
        for (var x = 0; x < fields.length; x++) {
            g_form.setReadOnly(fields[x], true);
        }
    }
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

AndersBGS
Tera Patron
Tera Patron

Hi @Abhilasha G T ,

 

Always utilize the ServiceNow solution instead of scripting - this is best practice. 

 

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

Hi Anders,

Thanks for your reply, i need the script to do in UI Policy only,

My Concerns is in future if any new fields added, so no need of creation again UI Policy action for that.

So i need a script to achieve this in UI Policy only.

 

Regards,

Abhilasha G T

 

Medi C
Giga Sage

Hello @Abhilasha G T,

 

This would be easily achieved by a WRITE ACL instead.

 

Could you please go to your Access Control (ACL)  check the interaction write ACLs and edit them by adding the condition "State is not closed"?


If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.

J Siva
Tera Sage

Hi @Abhilasha G T 

Try below sample client script to make fields read-only on SOW view. You can use the same section the UI policy "Execute if true" script section.

Screenshot_20250326-201950.pngScreenshot_20250326-202126.png

Hope this helps.

Regards,

Siva