- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-24-2015 02:54 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2016 02:57 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-30-2016 05:18 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
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.