Hide variable choice based on another field in a Service Catalog item

daniellethomson
Tera Expert

I have an onChange script I'd like to run on a catalog item but my script doesn't seem to be working. Any thoughts?

function onChange(control, oldValue, newValue, isLoading) {

  if (isLoading || newValue == '') {

  return;

  }

var type = g_form.getValue('employee_type');

  if(type == 'Contractor' || type == 'Consultant'){

      g_form.removeOption('company','92944b3937e4c280e96da6d2b3990ecf');

  }

}

1 ACCEPTED SOLUTION

No I don't think that is possible. Since it is a reference field but you are just displaying it as a drop down menu. You need to use reference qualifier on this field. But I don't think you can dynamically remove the option yet not removing the record from the reference table.


View solution in original post

13 REPLIES 13

Got you. If company is a reference field. You will have to use setValue(). Use this



function onChange(control, oldValue, newValue, isLoading) {


  if (isLoading || newValue == '') {


  return;


  }



var type = g_form.getValue('employee_type'); // make sure this is a correct variable/ field name


  if(type == 'Contractor' || type == 'Consultant'){ // put the choice values not the choice labels


      g_form.setValue('company','');


  }


}


Is there any other option? What they are looking to do is to remove one company from being visible and allow the end user to pick from a   list of other companies.


No I don't think that is possible. Since it is a reference field but you are just displaying it as a drop down menu. You need to use reference qualifier on this field. But I don't think you can dynamically remove the option yet not removing the record from the reference table.


Well shoot. Thank you for the clarification.