Help with code

B_pppppp
Tera Contributor

I try to check if this reference field is null (has no values to choose from) - not only empty. 

11 REPLIES 11

Astik Thombare
Tera Sage

Hi @B_pppppp ,

 

Could you try below code 

 

 

function onLoad() {
  // Get a reference to the business_service control
  var fieldObj = g_form.getControl('business_service');

  // Check if control exists and there's more than one option
  if (fieldObj && fieldObj.options.length != 1) {
    // Set business_service field to mandatory
    g_form.setMandatory('business_service', true);
    
  }
}

 

           If my reply helped with your issue please mark helpful 👍 and correct ✔️ if your issue is resolved.

 

                         By doing so you help other community members find resolved questions which may relate to an issue they're having

 

 

Thanks,

 

Astik

 

@Astik Thombare  Thank you but it doesn't work

Maddysunil
Kilo Sage

@B_pppppp Please try with below 

 

 

function onLoad() {
  // Get a reference to the business_service field
  var fieldObj = g_form.getControl('business_service');

  // Check if control exists and if the field is empty
  if (fieldObj && g_form.getValue('business_service') == '') {
    // Set business_service field to mandatory
    g_form.setMandatory('business_service', true);
  }
}

 

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks

@Maddysunil , thank you! It works a little too well now: it makes the field mandatory even if I can't choose any value for it because there's none