How to make field read only in ui page until value is not selected
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2025 04:32 AM
Hi All,
I want to make fields only read-only on the basis of selection of that the second filed become editable.
for example I created 3 fields 1. caller and 2. caller department and 3. call location.
Now I want caller department and caller location should be readonly until caller is selected how I can do that in ui page .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2025 07:47 AM
@Ankur Bawiskar thankyou so much for your time but this is what I am looking for Solved: Re: Reference field read only issue in ui page - ServiceNow Community
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2025 06:52 PM
the links I shared should also work
In the 2nd link I shared it's making readonly editable based on condition, you can enhance it based on change of 1st field
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2025 06:44 AM
I would use client scripts for this. One the runs 'onLoad' with the following logic:
function onLoad() {
// Check if u_caller is empty
var caller = g_form.getValue('u_caller');
if (!caller) {
g_form.setReadOnly('u_caller_department', true);
g_form.setReadOnly('u_call_location, true);
}
}
and another that runs 'onChange' for the "caller" field with logic:
function onChange() {
// Check if u_caller is empty
var caller = g_form.getValue('u_caller');
if (!caller) {
// clear any values in the two fields
g_form.setValue('u_caller_department, '');
g_form.setValue('ucall_location, '');
g_form.setReadOnly('u_caller_department', true);
g_form.setReadOnly('u_call_location, true);
}
else {
g_form.setReadOnly('u_caller_department', false);
g_form.setReadOnly('u_call_location, false);
}
}