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

damodarreddyp
ServiceNow Employee
ServiceNow Employee

kkim,



can you check on ui policy works on load as well.. as i see the client script is running on load..



In Advanced view of UI policy:


Screen Shot 2017-01-25 at 10.11.31 PM.png


Yes, all 3 policies are set to onLoad. These policies work fine without any scripts running.


Can you screenshot the conditions on the 3 properties?


find_real_file.png


find_real_file.png


This last one is purely for a read only policy of one of fields. Does nothing else.


find_real_file.png



I'm pretty sure that the UI policies are not the culprit since it works fine with GlideRecord query. This is what occurs when I use the Ajax version. The option is selected but nothing below it via the UI policy appears. I have to mouse click it to have it appear.



After the script runs


find_real_file.png


After clicking the option for project.


find_real_file.png