how to make field mandatory,read only,hide using client script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2017 11:23 PM
how to make field mandatory,read only,hide using client script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2017 11:29 PM
Hi Varun,
Check the below link for reference,
http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)#gsc.tab=0
Thanks,
Priyadarshini
PS: Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2017 11:32 PM
Here are the methods to use in client script but I recommend not to go for client script to perform the above three actions instead use UI policies..
g_form.setMandatory("fieldName", true)
g_form.setReadOnly("fieldName", true)
g_form.setDisplay("fieldName", true) or g_form.setVisible("fieldName", true)
Ref: http://wiki.servicenow.com/index.php?title=Differences_Among_Scripts#gsc.tab=0

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2017 11:36 PM
Hi Varun,
As per ServiceNow best practices always use UI policies/ACL's for your requirement.
If it is not achieved by above methods, use below script code for client script - onLoad
g_form.setMandatory("fieldName", true);
g_form.setReadonly("fieldName", true);
g_form.setVisible("fieldName", true);
I hope this helps 🙂
- Gopal Dutt Harbola
PS: Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2017 11:34 PM
HAI VARUN,
By using GlideForm (g_form) you can do this.
void setMandatory(fieldName, boolean)
- Makes the field required if true.
- Best Practice: Use UI Policy rather than this method whenever possible.
- Parameters:
- fieldName - specifies the field.
- boolean - true if mandatory, false if optional.
- void setReadOnly(fieldName, boolean)
- Makes the field read-only if true, editable if false. To make a mandatory field read-only, you must first remove the mandatory requirement for that field by using the setMandatory method.
- Note: Both setReadOnly and setReadonly are functional.
- Best Practice: Use UI Policy rather than this method whenever possible.
- Parameters:
- fieldName - specifies the field.
- boolean - true if read-only, false if editable.
- void setVisible(fieldName, boolean)
- Displays the field if true. Hides the field if false.
- If the field is hidden, the space is left blank. This method cannot hide mandatory fields with no value.
- Best Practice: Use UI Policy rather than this method whenever possible.
- Parameters:
- fieldName - specifies the field to be displayed or hidden.
- boolean - true to display the field, false to hide the field.
referred ServiceNow Wiki
- for more functions go through this link-