Pass choice values from script includes and have field in catalog client script display those values in the variable on the record producer (dependency).

claudine_warren
Kilo Expert

I have a script include and catalog client script (below).

My alert shows a comma separated list of subcategory value, subcategory label for all the correct choices based on the dependency to category.  My only issue is getting those values "into" the variable to be displayed on the record producer when the corresponding category is chosen. 

Thank you in advance.

find_real_file.png

1 ACCEPTED SOLUTION

claudine_warren
Kilo Expert

We got it done internally.

The updated Catalog Client script is below.  It all works beautifully now.

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

g_form.clearOptions('u_subcategory_task');
var ga = new GlideAjax('CatSubcatChoices2');
ga.addParam('sysparm_name','Choices');
ga.addParam('sysparm_cat',g_form.getValue('u_category_task'));//Tested this is correct
ga.getXML(function(response) {
var msg = response.responseXML.documentElement.getAttribute('answer').split(',');

for(var i=0;i < msg.length; i++){
g_form.addOption("u_subcategory_task", msg[i], msg[i]);//

}

}


);
}

 

View solution in original post

7 REPLIES 7

John Longhitano
Kilo Guru

What type of field is the variable?

It is a select box.

Instead of g_form.addOption("u_subcategory_task", msg[i].getDisplayValue.value, msg[i].label);

have you tried msg[i].getDisplayValue('value'),

or msg[i].value

 

If that doesn't work you may want to try pushing to the array differently in the script include.

You could do:

 

subcats.push({

value: gpSub.value.toString(),

label: gpSub.label.toString()

});

 

then you should be able to refer to 

msg[i].value and msg[i].label with no issue.

claudine_warren
Kilo Expert

I should have mentioned in my original post, this is a scoped Application (Customer Service).  So the regular method of clearing options and adding options within just a client script will not work.  SN Support suggested the using of a script includes and catalog client scrip using Ajax to get this done.