We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

All fields should be readonly once the state is changed to Closed Complete on catalog task

saichandu rayal
Kilo Contributor

When state is closed complete, it should make all the fields read only.

1 ACCEPTED SOLUTION

cx2162
Tera Guru

Write the following client script :

 

if(g_form.getValue('state') == 3){

var x = g_form.getEditableFields();

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

g_form.setMandatory(x[i], false);

g_form.setReadOnly(x[i], true);

}

}

View solution in original post

5 REPLIES 5

Hi, I have so similar question. I want to make all fields only readable when the status is closed or canceled for Change requests and for Change tasks. 

I have this code in Client script onchange at first for field "state = closed":

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    var model = g_scratchpad.change_model;
    var fields = g_form.getEditableFields();
    if (isLoading || newValue === "" || !model)
        return;

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

Is it right or what I have to change, because its not working in the moment. 

Kind regards

Nicole