Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

UI Policy

Ramkumar Thanga
Mega Sage

Please ignore this

 

I have a on submit client script as below

        If location ='s X > it makes the additional field mandatory and adds a field message.

But, is it possible to do the reverse?  It is achievable by a client script but not through a UI policy. :[This is needed because when the user tries to change the location from X the additional field which was mandated is not getting reversed.]

        If location is not 'X' > to make the additional field non-mandatory and hide the field message.

2 REPLIES 2

Rajesh Chopade1
Mega Sage

hi @Ramkumar Thanga 

yes it is possible using onSubmit client script, you just need to add else condition in your script as bellow:

else {
        g_form.setMandatory(additionalField, false); // Replace with the actual field name you want to make mandatory/non-mandatory

        g_form.hideFieldMsg(additionalField);
    }

Robbie
Kilo Patron
Kilo Patron

Hi @Ramkumar Thanga,

 

This should absolutely be possible via a UI Policy, however, as requested, to set this via a Client Script simply leverage an 'If' statement and the g_form method of .setMandatory('field_name', boolean) as below:

 

if(g_form.getValue('location_field_name') == 'X'){
      g_form.setMandatory('field_name', true);
}
else{
      g_form.setMandatory('field_name', false);
      g_form.hideFieldMsg('additional_field_name');
}

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.



Thanks, Robbie