- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2020 06:43 AM
g_form.setReadOnly() method not working when I run it through Client Script, but it works when I run the same on the JavaScript Executor(Ctrl + Alt + Shift + J), is there a way to debug and know what is stopping my Client Script code to not work on setting the field read only.
The Client Script is:
Solved! Go to Solution.
- Labels:
-
Script Debugger
-
User Interface (UI)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2020 07:59 AM
Are there any UI policies that are conflicting with your client script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2020 07:38 AM
Hi Rahul,
Put the g_form.setReadOnly('item', true); after completing the first brace. It will work both mandatory and readonly function.
Regards,
Suresh.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2020 08:11 AM
What UI type is your client script set to?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2020 08:20 AM
Desktop

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2020 08:21 AM
I'm not sure if ServiceNow supports forEach in scripts. Can you try converting it to a for loop?
for( var i = 0; i < fieldsArray.length; i++) {
g_form.setReadOnly(fieldsArray[i], true);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2025 01:13 PM
Check if your client script is in the same scope of the field.