Client script

Maidhili_G
Mega Contributor

Set all the fields Read Only based on selection of particular choice in a field (state = cancelled)

4 REPLIES 4

folusho
Tera Guru

@Maidhili_G 

 

You can use an onChange Client script or UI Policy. Then use the code below:

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

Sandeep Rajput
Tera Patron
Tera Patron

@Maidhili_G 

function onLoad() {
    var stateValue = g_form.getValue('state');

    // Ensure this matches the actual value of the "Cancelled" choice in your state field
    if (stateValue === 'cancelled') {
        var fields = g_form.getEditableFields();

        for (var i = 0; i < fields.length; i++) {
            g_form.setReadOnly(fields[i], true);
        }

        // Optional: keep the 'state' field editable to allow reverting
        // g_form.setReadOnly('state', false);
    }
}

Zach N
Tera Guru

Is this for the Incident Table? If so there should already be an OOTB UI Policy for this named Make fields read-only on close (at least there was in my PDI).

 

If this is for another table, you could always copy that UI policy and apply it to a different table (Though creating each UI Policy action could get tedious).

Otherwise folusho's suggestion will be the quickest.

Harish Bainsla
Kilo Patron
Kilo Patron

Hi @Maidhili_G  try below code i have test it on pdi and also you can make by ui policy 

Screenshot 2025-05-25 at 7.54.26 AM.png

Screenshot 2025-05-25 at 7.55.07 AM.png

if my answer helps you mark helpful and accept solution