Make all fields read only when active = false
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 02:20 AM
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);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 02:39 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 03:10 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 03:16 AM
This code works well for active incidents but not for inactive incidents, some of the fields are still editable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 03:27 AM
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