All the fields get read only when incident closed

nowitsvashu
Tera Guru
Please help me with this script(I've created a custom incident form)

function
onLoad() {
    //Type appropriate comment here, and begin script below
    var incidentState = g_form.getValue('state');
    var editableFields = g_form.getEditbleFields();

    if(incidentState == 7){
        for(var i = 0; i < editableFields.length; i++){
            g_form.setReadOnly(editableFields[i],true);
        }
    }
}
7 REPLIES 7

Shaheensk
Kilo Expert

Hi @nowitsvashu ,

It looks like there is a small typo in your code. The function getEditbleFields() should be getEditableFields().


var incidentState = g_form.getValue('state');
var editableFields = g_form.getEditableFields(); // Fix typo in function name

if (incidentState == 7) {
for (var i = 0; i < editableFields.length; i++) {
g_form.setReadOnly(editableFields[i], true);
}
}

AndersBGS
Tera Patron
Tera Patron

Hi @nowitsvashu ,

 

OOTB all fields will become read only when incident is closed - so why create a script for something that is already made OOTB? What is the business case?

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

best regards

Anders

  

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

Aman Kumar S
Kilo Patron

Hi @nowitsvashu 

I believe its already an OOB feature, you can check Incident.* Write ACL where in the condition it is mentioned

AmanKumarS_0-1708932300540.png

 

Also, Using client script or UI polciy is not the best idea for your requirement, as these only works for form layout, it will still expose the incidents to be updated from LIST layout unless you block it using list edit ACL or have an onCellEdit client script which is unnecessary effort.

Best way to secure updation is ACL.

 

 

Best Regards
Aman Kumar