- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
For those of you working with Category + Subcategory fields, you know how much of a pain it was to initially set them up. Your Category choices are defined in the sys_choice table by table, element ("category"), value... and then you create other entries for table, element ("u_subcategory"), value, dependent value. Then you relate which thing it's looking to for that dependent value on the dictionary entry for the subcategory item.
Anyways, once you have a Category + Subcategory, if you want those to show up and actually filter the Subcategory down dynamically on a Record Producer, you'll need to use AJAX in client scripts to make server calls since a Record Producer usually only submits info to the server upon submission.
The category variable on the Record Producer should work fine without any tweaking cause it's looking at the correct table & element in the choice list table. The problem arises when you look at the subcategory and it shows ALL choices because it doesn't dynamically query the choices against the dependent value.
Stay with me, so you can make a reference qualifier on the Subcategory variable to limit the choices based on a dependency... but since the record producer isn't a real "living record" yet you have to force it to update. Once the variables are attached to a real record, this reference qualifier should work normally so your client script isn't going to need to run on Requested Items or Catalog Tasks or anything... just in the Catalog Item View.
The Subcategory variable (lookup select box) should be looking at the sys_choice table and have a reference qualifier similar to:
javascript:'name=incident^element=u_subcategory^dependent_value=' + current.variables.category
Then an onChange client script that runs whenever category is changed will feed variables to a script include and you might want to use this same script include for multiple tables so lets make the script include first:
var DenburyAjax = Class.create();
DenburyAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getSubcategories: function() {
var table = this.getParameter('sysparm_table');
var element = this.getParameter('sysparm_element');
var category = this.getParameter('sysparm_category');
var choice = new GlideRecord('sys_choice');
choice.addQuery('name',table);
choice.addQuery('element',element);
choice.addQuery('dependent_value',category);
choice.orderBy('sequence');
choice.query();
while(choice.next()) {
if (!choice.inactive) {
var item = this.newItem("item");
item.setAttribute('label', choice.label);
item.setAttribute('value', choice.value);
}
}
}
});
Make sure you check the "Client Callable" box.
Now to feed the category value to that and build the choices on subcategory, your catalog client script should run onChange of the category variable and only the Catalog Item View:
function onChange(control, oldValue, newValue, isLoading) {
if ((isLoading) || (newValue == ''))
return;
var aj = new GlideAjax("DenburyAjax");
aj.addParam("sysparm_name", "getSubcategories");
aj.addParam("sysparm_table", "incident");
aj.addParam("sysparm_element","u_subcategory");
aj.addParam("sysparm_category", newValue);
aj.getXML(getResponse);
}
function getResponse(response) {
var items = response.responseXML.getElementsByTagName("item");
g_form.clearOptions('u_subcategory'); //has to clear previous buildout
g_form.addOption('u_subcategory','','-- None --');
for (var i = 0; i < items.length; i++) {
var item = items[i];
var value = item.getAttribute("value");
var label = item.getAttribute("label");
g_form.addOption('u_subcategory', value, label);
}
}
Make sense? Any questions?
- « Previous
-
- 1
- 2
- Next »
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.