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

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

Community Alums
Not applicable

In the client side script you can use below code.
Also  you can do this with ACL as well as that's the most preferred way of doing it.

 var fieldname = g_form.getEditableFields();
         for (var x = 0; x < fieldname.length; x++) {
           g_form.setReadOnly(fieldname[x], true);
}