Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
var fieldToHide = 'subcategory'; // I have taken subcategory as an example
if (newValue === '') {
g_form.setDisplay(fieldToHide, false);
return;
}
var ga = new GlideAjax('NumberOfDependentChoices');
ga.addParam('sysparm_name', 'getCountOfDependentChoices');
ga.addParam('sysparm_tableName', g_form.getTableName());
ga.addParam('sysparm_element', fieldToHide);
ga.addParam('sysparm_choiceName', newValue);
ga.getXMLAnswer(callBack);

function callBack(answer) {
g_form.setDisplay(fieldToHide, parseInt(answer) > 0 ? true : false);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var NumberOfDependentChoices = Class.create();
NumberOfDependentChoices.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCountOfDependentChoices: function() {
var dependentChoiceCount = 0;
var choiceName = this.getParameter('sysparm_choiceName');
var tableName = this.getParameter('sysparm_tableName');
var element = this.getParameter('sysparm_element');
var choiceCountGa = new GlideAggregate('sys_choice');
choiceCountGa.addAggregate('COUNT');
choiceCountGa.addQuery('dependent_value',choiceName);
choiceCountGa.addQuery('inactive','false');
choiceCountGa.addQuery('name',tableName);
choiceCountGa.addQuery('element',element);
choiceCountGa.query();
while(choiceCountGa.next()){
dependentChoiceCount = choiceCountGa.getAggregate('COUNT');
}
return dependentChoiceCount;
},
type: 'NumberOfDependentChoices'
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Hide the dependent choice field when there are no available options for the selected parent choice.

For example, if a selected category on the incident form has no subcategories, then the subcategory field should be hidden.

The file NumberOfDependentChoices.js is a client callable script include file which has a method which returns number of dependent choices for a selected choice of parent choice field.

HideDepnedentField.js is client script which hides the dependent choice field(ex:subcategory field on incident form) if there are no active choices to show for a selected choices of it's dependent field (example: category on incident form)
Loading