Make all form fields read-only (client script)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-13-2011 11:49 PM
Hi,
I need to put all the fields of a form read-only. I need to use a client script for that, because in certain case I will need to have some fields editable.
Is there another way than put all the fields in a ui policy (or a client script)?
Is suppose there is a way to do such a thing :
get references to all fields of the form
while(...)
{
referenced field.setreadOnly()
}
Thanks a lot
rgds
Xavier
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-02-2018 10:12 PM
You need to select 'All' in the Script Tab for the field 'Run scripts in UI type'. Then it will work for Mobiel as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2019 05:31 PM
Thank you for this! I was having some difficulties creating an access control that does the same thing. But this works like a charm.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2023 06:19 AM
This is working fine for platform, but not for agent workspace.
Do you have any alternate suggestion for that?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2024 04:38 AM
Sure, you can make all form fields read-only using a client script in ServiceNow. Here's a sample code: javascript function onLoad() { //Loop through each field in the form var control = g_form.getControl('variable_name'); for (var i = 0; i < control.length; i++) { //Make each field read-only g_form.setReadOnly(control[i].name, true); } } Here are the steps to implement this: 1. Navigate to System Definition > Client Scripts in ServiceNow. 2. Click on New to create a new client script. 3. Fill in the necessary fields: - Name: Give a name to your client script. - Type: Select "onLoad". - Table: Select the table where you want to apply this script. 4. In the Script field, paste the above code. 5. Click on Submit to save the client script. Please replace 'variable_name' with the actual field name you want to make read-only. This script will make all fields read-only when the form loads. nowKB.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2024 05:24 AM
Hi
You can simply use below code
var getFields = g_form.getEditableFields();
for(var i=0;i<getFields.length;i++)
{
g_form.setReadOnly(getFields(i),true);
}