Client Script Not Marking Particular Field as Read-Only

jlaps
Kilo Sage

We have a client script on CHG to mark all fields as READ ONLY for normal users when state is closed. This works as expected except for one field "type", which is not getting set read only. I did find the article about MANDATORY fields that are "blank" not being set this way, which accounts for the USE RUNBOOK below, and I get that. But why is TYPE not being set to RO?

I even added a specific line to try and force it in case the for loop was missing it for some reason. Ideas?

function onLoad() {
    var isAdmin = g_user.hasRole('admin');
    //if(!isAdmin)
    //{
    var changeState = g_form.getValue('state');
    if (changeState == '8' || changeState == '9' || changeState == '12') {
        if (!isAdmin) {
			g_form.setReadOnly('type', true);
           var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
    g_form.setReadOnly(fields[x], true);
}
        }
    }
}
4 REPLIES 4

Community Alums
Not applicable

Hi,

Any issues while using a UI policy instead of using Client Scripts?

 

Musab Rasheed
Tera Sage
Tera Sage

Hello,

Check this out ?

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0694722

Regards

Please hit like and mark my response as correct if that helps
Regards,
Musab

Allen Andreas
Administrator
Administrator

Hi,

This usually happens when there's possibly a competing UI Policy or Client Script doing something else with that field. Can you check for this field being specified/used somewhere else?

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

jlaps
Kilo Sage

There is no conflicting UI policy, and though I created a new UI policy added for just this field, it is still not flagging as RO.

I am not sure about that KB article- still looking into it.