Make all fields read only when active = false

Sahar_Kaizer
Tera Contributor

Hi,

I'm attempting to use a client script to make all the fields read-only when an incident is inactive. The following code works well for inactive incidents and makes all fields read-only. However, it doesn't work as expected when the incident is active because some fields remain read-only.

Thank you,

Sahar

 

function onLoad() {
var active = g_form.getValue('active');

// Get all form elements
var formElements = g_form.elements;

for (var i = 0; i < formElements.length; i++) {
var element = formElements[i];

// Check if the element is not the "active" field itself
if (element.fieldName != 'active') {
// Set all fields except "active" to read-only when "active" is false
g_form.setReadOnly(element.fieldName, !active);
}
}
}

Sahar_Kaizer_0-1694683138602.png