- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-29-2019 09:01 PM
How to clear the value and how to Mandatory Please help me out
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-29-2019 10:49 PM
Hello Chandra,
1. With the help of UI Policy and UI Policy Action you can clear the value or set mandatory or Set visibility as well
2.Another option, you can use below scripts:
- clearValue(String fieldName) :Removes any value(s) from the field.
-
setDisplay(String fieldName, Boolean display) :Displays or hides a field.
-
setMandatory(String fieldName, Boolean mandatory)
Makes the specified field mandatory.
Whenever possible, use a UI policy rather than this method.
g_form.setMandatory('field name', true);
g_form.setDisplay('field name', true);
g_form.clearValue('field name');
Please mark as Correct Answer and Helpful, if applicable.
Thanks!
Abhishek Gardade
Hexaware Technologies
Abhishek Gardade

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-29-2019 09:09 PM
Hi
You can use clear value as well as setValue.
https://developer.servicenow.com/app.do#!/api_doc?v=london&id=r_GlideFormClearValue_String
If it is a reference field you need to do something like this -
g_form.setValue("reference_field_name","");
For setting it mandatory you can use setMandatory function of g_form -
Hope this helps.
Regards,
Omkar Mone
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-29-2019 09:47 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-29-2019 09:50 PM
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
// if (isLoading || newValue === '') {
// return;
// }
g_form.setValue("ca_template","");
g_form.setMandatory('ca_template', true);
//Type appropriate comment here, and begin script below
}
is it correct please help me out

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-29-2019 10:37 PM
Hi
Try this script -
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.setValue("ca_template","");//if it is a reference field
g_form.clearValue("ca_template");//if it is a reference field
g_form.setMandatory('ca_template', true);//set this field to mandatory
}