set fields to read only when caller changes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2024 08:42 AM
I have a client script that is onChange when the caller field is changed it populates a bunch of other fields on the form like end user_ Phone , dept, address, title, location, work status etc. I want to have the client script after the AJAX is done populating to check if the fields are populated if so set them to read only and if now leave them open.
1. issue is that the fields are not getting set to read only until the caller field is changed a second time so the inital change it is not working
2. some field read only for instance the phone in one user is populated then if the user is changed it stays read only even if the changed users phone is not populated.
here is my code so far
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var additionalInfoFields = ['user_email', 'user_phone', 'user_status', 'user_building', 'user_room'];
additionalInfoFields.forEach(function(fieldName) {
var fieldValue = g_form.getValue(fieldName) ? true : false;
g_form.setReadOnly(fieldName, fieldValue);
});
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2024 10:01 AM
Hi @ServNowDev ,
Why don't you set fields read only during AJAX response, check if response has a value if yes update and set the field read only
Also check if any these fields read only on the dictionary level( By default) or any other UI Policies/client scripts/ACLs conflicting
You may also take care when form loads (Onload if its needed)
Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2024 10:10 AM
Are these the correct field names? They do not appear to be out of the box fields for incident (I'm guessing incident as that is the only table I can this of with a caller field). Since these are not out of the box they should have u_ at the beginning of the name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2024 07:20 AM
these are custom field and used as example from the real instance.