g_form.setValue not initiating UI Policy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2017 08:04 AM
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);
}
}
}
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2017 08:43 AM
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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2017 09:04 AM
Yes, all 3 policies are set to onLoad. These policies work fine without any scripts running.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2017 09:51 AM
Can you screenshot the conditions on the 3 properties?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2017 01:09 PM
This last one is purely for a read only policy of one of fields. Does nothing else.
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
After clicking the option for project.