Grey out fields

avani2
Giga Contributor

How to grey out all fields except one on a form when update button is clicked ?

I want to make child incidents uneditable but only parent incident field is editable once user click on Update Button

5 REPLIES 5

Michael Fry1
Kilo Patron

You should use an ACL to make fields read-only if 'Parent' field is not empty.


felipe_barbosa
ServiceNow Employee
ServiceNow Employee

There is several ways to do it. You can use UI Policies, onChange client scripts, etc, but all of these are not security per se, only cosmetic, Security comes with ACL.



In your scenario, when the update button is clicked, does a status change or something like this? Let me know and we can start drawing a solution for you.


avani2
Giga Contributor

if I write a UI Policy,


do I need to write g_form.setReadonly for each field present on the form.


Is there any other way to make all fields read only except one on form


Hi Avani,



You can try to use a script on the UI Policy to make all fields readOnly (and add a if fieldname != something to skip a field from readOnly) and use DOM elements to make all readOnly. Your script will look something like this:


      var list = document.getElementsByClassName("form-group");


        var x=0;


        for (x=0; x<list.length; x++) {


        console.log(x);


        var element = list[x].getElementsByTagName("input");


        var field = element[0].name;


        var fieldName = field.split(".");


     


        if(fieldName[2] !== undefined) {


        var fn = fieldName[2];


        g_form.setReadOnly(fn, true);


        //console.log(fn);


        }


          }



It needs a bit of work but it goes around this.



Best regards,



Felipe