g_form.setValue not initiating UI Policy

KB15
Giga Guru

I've recently created an Ajax script (my first attempt) and things seem to be working however I found the behavior of the g_form.setValue to be unusual. I'm on Helsinki Patch 6.

The field type is multiple choice. I have two options, business unit and project. There's a UI policy on the variable set to show specific fields based on what is selected. The Ajax script automatically sets the "project" option based on the user. The radio button option is set visually (ie filled in) but the UI policy doesn't kick in. It only kicks in if I click on the "project" option.

The UI policy works fine with a catalog client script using GlideRecord but not with this script. Just as an note, the field "charge_method" is supposed to be hidden but one of the options is selected via script to turn on the UI policy. Selecting a hidden option also works fine using GlideRecord. Alternatively, I've changed the visibility on this field and I still get the same result.

For reference, this is the client script. Is there something missing? Does Ajax not work with UI policies?

function onLoad() {

  var id = g_user.userID;

  var ga = new GlideAjax('FindEmployeeNumber');

  ga.addParam('sysparm_name', 'getUserID');

  ga.addParam('sysparm_ID', id);

  ga.getXMLAnswer(stateCallback);

  function stateCallback(answer) {

  //alert(answer);

  if (answer != true) {

  g_form.setValue('charge_method', 'project');

  g_form.setDisplay('charge_method', false);

  g_form.setDisplay('label_charge_method', false);

  }

  }

}

6 REPLIES 6

Do the two UI Policies have UI Policy actions against any of the same fields?


They do not. Two of the policies act on two separate sets of fields. One is for the BU and the other is for the project. I also corrected my last message to say I believe it's not the policies and not the other way around.