how to field mandatory in clientscript using onload
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2017 10:28 PM
how to field mandatory in clientscript using onload
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2017 12:24 PM
Client Script type should be onLoad
Here is the sample script:
function onLoad() {
g_form.setMandatory('field_name', true);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2017 12:18 AM
thank's bro
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2017 12:26 PM
Hello Kishore,
Below link will help you:
Make field mandatory using client script
Thanks,
Abhishek
If this reply assisted you, please consider marking it Correct, Helpful, or Like it.
This helps other customers to learn from your thread.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-08-2017 12:29 PM
Hi Kishore.
if you have not any logic in your business need then i would recommend your to use UI Policy to make field "Mandatory", "Read Only","Visible".
Creating a UI Policy - ServiceNow Wiki
through script:
function onLoad() {
g_form.setMandatory('<field_name>',true); //pass true to make mandatory . false to not make mandatory.
}
11.3 setMandatory
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.
- Returns:
- void