Making a field required based on another field question

Community Alums
Not applicable

I have a field on a form that the business would like to be required if another field is set to "Deploy". 
I think a client script is probably the correct route to go but would like to ask the question,

 

Which is the best way to make the field required if the status field changes to "deploy" and not required if it's not "deploy"?

Business rule?
UI Policy?

Client Script?

Again I'm leaning toward client script with an OnChange and I'll probably have to use an IF statement in there but could use some help with that if someone could offer some sample code.

1 ACCEPTED SOLUTION

Valmik Patil1
Kilo Sage

Hello ,

You can use below script in onChange client script

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
    if(newValue == 2){ // instead of "2" give background value of your field
        g_form.setMandatory('assignment_group', true);  // your field name to make it mandatory
       
    }else{
        g_form.setMandatory('assignment_group', false); // your field name to make it non mandatory

    }
   
} 

 Also easy way to do it using UI policy with no code.

Thanks ,

Valmik Patil 

View solution in original post

5 REPLIES 5

AndersBGS
Tera Patron
Tera Patron

Hi @Community Alums ,

 

There is no reason to due a script here. Just use a UI policy to set field mandatory based on field value deploy.

 

If my answer has helped with your question, please mark m answer as accepted solution and give a thumb up.

 

Best regards

Anders

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

Valmik Patil1
Kilo Sage

Hello ,

 

Yes you can do it using client script or UI policy, easiest way would be to use UI policy which requires not code

Also we can do it using script as below

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
    if(newValue == 2){   // instead of "2" give your value of variavle
        g_form.setMandatory('assignment_group', true);  // give your field name and it makes mandatoy
    }else{
        g_form.setMandatory('assignment_group', false); // give your field name and it makes non -mandatoy
    }
   
} 

Please let me know if you need any other help.

Thanks and Regards,

Valmik Patil

Valmik Patil1
Kilo Sage

Hello ,

You can use below script in onChange client script

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
    if(newValue == 2){ // instead of "2" give background value of your field
        g_form.setMandatory('assignment_group', true);  // your field name to make it mandatory
       
    }else{
        g_form.setMandatory('assignment_group', false); // your field name to make it non mandatory

    }
   
} 

 Also easy way to do it using UI policy with no code.

Thanks ,

Valmik Patil 

Community Alums
Not applicable

Thank you, this was close but I had to use a script instead of a UI policy for other reasons.  It was close but I had to look at 2 thing if they changed, but your solution would be acceptable if only 1.