Client Script Not Marking Particular Field as Read-Only
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-30-2022 08:11 AM
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);
}
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-30-2022 08:15 AM
Hi,
Any issues while using a UI policy instead of using Client Scripts?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-30-2022 08:16 AM
Hello,
Check this out ?
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0694722
Regards
Regards,
Musab

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-30-2022 08:17 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-30-2022 10:51 AM
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.