How to clear the value and Mandatory

Naveen31
Giga Contributor

How to clear the value and how to Mandatory Please help me out

1 ACCEPTED SOLUTION

AbhishekGardade
Giga Sage

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

 

Thank you,
Abhishek Gardade

View solution in original post

8 REPLIES 8

Omkar Mone
Mega Sage

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 - 

https://developer.servicenow.com/app.do#!/api_doc?v=helsinki&id=r_GlideFormSetMandatory_String_Boole...

 

Hope this helps.

Regards,

Omkar Mone

find_real_file.png

 

Is it Correct? Please help me out

Naveen31
Giga Contributor

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

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

}