
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2019 01:57 AM
Hey,
SO strange. I need help here!
I have a scoped variable set up as a lookup select box and link to a custom table that contains similar entries like sys_choice ... to be used for the lookup.
I'm using a ref qual condition that works fine when choosing valid entries from the table within a catalog item ... All fine!
No I need for certain cases (depending on a change mad in an other variable) to ADD an OPTION that is NOT part of the table I'm using for my choices.
SO a have a catalog client script on change, that sets the ADDITIONAL option (not matching the ref qualifier) in case required (and I also found an way to remove it again in case the other value changes again ... ).
All works fine ... just the first time the option is to be set, it disappears again! Looks link there would be some other setting redoing what was just done in the catalg client script. I added an alert at the end of the client script and when it pops up the correct value is still there. Just overwritten with blank afterwards.
I 5 times checked ALL client scripts ... none of them can be responsible for overwriting.
And anyhow .. when changing the variable causing it .. back and force it works .. allways ... its JUST the first time this does not work ... anyone with an idea? Look more like a bug to me ...
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2019 06:10 AM
Table?! We are still talking about variables ..
BUT I found it myself. Its the reference qualifier I'm using to define what kind of values are valid on the lookup select box. This technically is most probably nothing else than a client script. As the values initially are set via the change on an other variable - this will be "loaded" afterwards. So I need to remove the ref qualifyer there and buid in the logic manually within a client script.
Anyhow ! Thnx for your effort!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2019 02:10 AM
The Ajax call is made in the onchange client script?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2019 02:14 AM
Yes. It's in a catalog item and scoped ... no other way to get the CI values into the variables via an other way ..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2019 02:25 AM
So, i have tried calling the GlideAjax and adding the option in onChange Client script. This adds the option to the dropdown list
Following is an example
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax("Utils");
ga.addParam ("sysparm_name", "getOptions");
ga.getXMLAnswer(response);
function response(answer){
g_form.addOption('addoption_catalog', answer, answer);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2019 02:28 AM
the on change run on an other variable (A) change ... and will set the option to variable B.
Will try to post my code here in some min.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-28-2019 02:43 AM
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var yyyClass = g_form.getValue('xxx_class');
var ga = new GlideAjax('x_xxx.yyyGetAjaxRecord');
ga.addParam('sysparm_name', 'getReference');
ga.addParam('sysparm_obj_Id', newValue);
ga.addParam('sysparm_obj_classId', yyyClass);
ga.getXML(ResponseAjax);
}
function ResponseAjax(response){
var answer = JSON.parse(response.responseXML.documentElement.getAttribute("answer"));
var choiceTmp ='';
var choiceisOk ='';
// remove options that are non-standard
choiceTmp = g_form.getValue('yyy_choice_tmp');
g_form.removeOption('yyy_choice_tmp', choiceTmp);
g_form.clearValue('yyy_choice_tmp');
// check if value for optional external appearance is standard sys choice
choiceIsOk = answer.choiceIsOk;
if (choiceIsOk == 'true') {
g_form.setValue('xxx_variable_B',answer.choice); // sets the choices a ajax confornfirms its a standard value
}
else { // no standard value in CI - add option and tmp variable to be able removing it again
choiceTmp = answer.choice; // non-standard - add option
g_form.addOption('xxx_variable_B', choiceTmp , choiceTmp);
g_form.setValue('xxx_variable_B', choiceTmp ); // tmp choice added
g_form.setValue('yyy_choice_tmp', choiceTmp ); // to keep new option to be able to remove it again
}
}
But as said before .. all works fine here. The issue seems to be outside. The standard choice (either none or if none not set the first possible choice) is set automatically the first time this field is getting filled ... . Just AFTER my script has filled it.