- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I make all fields on the Incident form read-only when the state is 'In Progress', and ensure they become editable again when the state changes to something else? I have tried this onChange script but it's working for when state is in progress. but revert to different then it not make it editable the field.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@Gajendra singh Try below onchange script on incident table for state field.
getEditableFields() only returns fields that are currently editable. When fields are already read-only, they won't be in the list, so your loop can't make them editable again.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) return;
toggleFields();
}
function toggleFields() {
var state = g_form.getValue('state');
var makeReadOnly = (state == '2');
// Get ALL fields on the form, not just editable ones
var allFields = g_form.elements;
for (var i = 0; i < allFields.length; i++) {
var fieldName = allFields[i].fieldName;
// Skip the state field itself
if (fieldName != 'state') {
g_form.setReadOnly(fieldName, makeReadOnly);
}
}
// Ensure state field is always editable
g_form.setReadOnly('state', false);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Gajendra singh , Glad my answer helped you, Can you please mark my answer as an Accepted Solution. As it might prove helpful for others as well.
Regards,
Saurabh V.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@Gajendra singh Try below onchange script on incident table for state field.
getEditableFields() only returns fields that are currently editable. When fields are already read-only, they won't be in the list, so your loop can't make them editable again.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) return;
toggleFields();
}
function toggleFields() {
var state = g_form.getValue('state');
var makeReadOnly = (state == '2');
// Get ALL fields on the form, not just editable ones
var allFields = g_form.elements;
for (var i = 0; i < allFields.length; i++) {
var fieldName = allFields[i].fieldName;
// Skip the state field itself
if (fieldName != 'state') {
g_form.setReadOnly(fieldName, makeReadOnly);
}
}
// Ensure state field is always editable
g_form.setReadOnly('state', false);
}
