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

 

4 REPLIES 4

Siva Jyothi M
Mega Sage

Hi @Sahar_Kaizer,

 

You can write a Read ACL with a condition as Active is false on Incident table and add the roles to the ACL.

 

Please mark this answer as correct and helpful if it solves your issue.

 

Regards,

Siva Jyothi M.

Rohit01998
Tera Guru

Hello @Sahar_Kaizer 

try below code...

function onLoad() {
 
 if(g_form.getValue('active')=='false')
{
var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
    g_form.setReadOnly(fields[x], true);
}
}
}

 

Please mark this answer as correct and Give 👍🏻 if it solves your issue...

Thanks,

Rohit

This code works well for active incidents but not for inactive incidents, some of the fields are still editable. 

Sahar_Kaizer_0-1694686586349.png

 

 

Actually this code should work for inactive incidents.

If some field are read only when "active = true" then try to figure it out if there is any Client script or UI policy applied on incident table