how to field mandatory in clientscript using onload

Kishore Babu S
Tera Contributor

how to field mandatory in clientscript using onload

4 REPLIES 4

Arindam Ghosh
Mega Guru

Client Script type should be onLoad



Here is the sample script:



function onLoad() {


g_form.setMandatory('field_name', true);


}


thank's bro


abhishekdash
ServiceNow Employee
ServiceNow Employee

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.


Harsh Vardhan
Giga Patron

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