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

Community Alums
Not applicable

Hi Chandra,

     Using Client Script: 

                  g_form.clearValue('field_name');      //Syntax for clearing value

                  g_form.setMandatory('field_name',true);     //Syntax for making the field mandatory

 

     Using UI Policy:

                   Provide the condition in ui policy and Add UI policy action for clearing value of the field and making field mandatory. 

                  In UI Policy Action there you can see the Checkbox for making field mandatory and clear the value of the field.

                  Using these you can achieve.

 

find_real_file.png

 

 

Please Mark as correct or helpful..!!

Regards,

Meghnath.

 

 

Hi Meghnath,

I have written below onload client script.

function onLoad() {

if(g_form.getValue('ca_template') == 'ee299dc2db38c050d71272143996198a'){
//alert('I am here');
g_form.setValue('ca_template',"");
g_form.setMandatory('ca_template', true);
//Type appropriate comment here, and begin script below
}
}

But the problem is if i give sys id CA Template module if i click it takes to schedule job and when we try to execute the new records gets created for different sys id,so my colleague suggested to modify the Transform Script in the transform map the values are taking from their only,but in the transform map where i need to modify.below is the transform map script.

 

answer = (function transformEntry(source) {
var ch = source.u_ca_template.toString();
var check = new GlideRecord('x_palad_cert_ca_template');
check.addQuery('dn',ch);
check.query();
if (check.next()){
var check1 = check.dn;
}
// Add your code here
return check1; // return the value to be put into the target field

})(source);

find_real_file.png

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

But The CA TEMPLATE is the reference field 

find_real_file.png

 

But if i select another DN i want to show, only for the Undefined DN i want to show blank and mandatory i have written below onload client script but its not working.

function onLoad() {

if(g_form.getValue('ca_template') == ''){
//alert('I am here');
g_form.clearValue('ca_template');
g_form.setMandatory('ca_template', true);

}
}