state closed= read only

Shir Sharvit
Tera Contributor

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:

ShirSharvit_0-1700485379856.png

 

This is the result, but I need the two fields that are not yet read-only to also be read-only
(service, service offering)

 

ShirSharvit_1-1700485413728.png

 

Thank.shir

 

7 REPLIES 7

Brad Bowman
Kilo Patron
Kilo Patron

You would have to make all fields not mandatory first. Try adding a line in your for loop

g_form.setMandatory(fields[x], false);

Peter Bodelier
Giga Sage

Hi @Shir Sharvit 

 

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.

Amit Gujarathi
Giga Sage
Giga Sage

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