Need to set choice list values from catalog client script

Ross Drew
Tera Contributor

I am trying to dynamically populate a list select box for a variable in a variable set that is pointed to the user reference field. I am getting back the sys_id of the users that I need to display as choices, but I cannot set the value on the choice list. Below is the onChange catalog client script. The variable type is "Lookup Select Box'.  Lookup from table is set to sys_user_grmember. Lookup value field is set to User. Any ideas?

 

 

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

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

      return;

   }

 

var usr_data = [];

 

//clears existing list values from the ref qualifier

g_form.clearOptions('variables.ref_field);

 

var ga = new GlideAjax('wxyz_utils');

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

ga.addParam('location',newValue);

ga.getXML(showMessage);

}

function showMessage(response) {

var answer = response.responseXML.documentElement.getAttribute("answer");

 

var usr_data = JSON.parse(answer);

var usr_data1 = answer.replace(/[\[\]"]+/g,'');//removes brackets and quotes

var usr_data2 = usr_data1.split(','); //to split the object variables for measuring length.

 

for (var i = 0; i<usr_data2.length; i++) {

 

 

//g_form.setValue('variables.ref_field’,usr_data2[i]); //this does not work

 

g_form.addOption('variables.ref_field’,usr_data2[i]); //this does not work

 

}

}

 

0 REPLIES 0