The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How to check whether a field is Read Only or not from Client Script.

Lohith
Giga Expert

Hi All,

Could you please help me in how to know whether a particular field is Read only or not from Client Script. Like i want to know whether a field "request_state" is read only or not in sc_request table from script.

Thanks and Regards

Lohith.

1 ACCEPTED SOLUTION

Hello,



We found a solution to this problem by inspecting the form HTML. For every field on the form ServiceNow generates a status span that keeps track of the current field input status. When the field is set to read-only, either by the server or through a client script, this field has the class 'read_only'. Therefore we use the following function to check if a field is readonly:



function( fieldname ) {


        var elem = document.getElementById( 'status.' + g_form.getTableName() + '.' + fieldname );


        return elem.hasClassName( 'read_only' );


}



Hope this helps!



Joris


View solution in original post

6 REPLIES 6

navakanth
ServiceNow Employee
ServiceNow Employee

Lohith,


I would recommend to use g_form.isDisabled(<field_name>) API. It does not work for catalog variables on req-item but this API should work for any Platform form. This will ensure compatibility for future releases.



You can use custom one for the catalog variables.


Thanks, Nava.


Thank you for this, looks like this still works.

I wish this would be in the documentation, to make it feel more "official" and thus dependable.