state closed= read only
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 05:05 AM
Hi
I need that when the state=closed then all the fields in the Incident form will become read only
I am attaching the code:
This is the result, but I need the two fields that are not yet read-only to also be read-only
(service, service offering)
Thank.shir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 05:13 AM
You would have to make all fields not mandatory first. Try adding a line in your for loop
g_form.setMandatory(fields[x], false);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 05:13 AM - edited 11-20-2023 05:15 AM
You need to remove the mandatory from these fields, before they can become read-only.
You could use
g_form.setMandatory(field[x],false)
However it would be better to set the complete record readonly by making sure your ACL's wouldn't allow write when the incident is inactive.
Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 05:41 AM
Hi @Shir Sharvit ,
I trust you are doing fine .
Please try the below code it should work
function onLoad() {
if (g_form.getValue('state') == 7) { // state is closed
var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
// Set the field to non-mandatory
g_form.setMandatory(fields[x], false);
// Then set it to read-only
g_form.setReadOnly(fields[x], true);
}
}
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi