Category/Subcategory dependency not working in the Service Portal

only1dallas
Kilo Contributor

Hi folks! How are you? So. I need to create the dependency between category and subcategory. It works on the back end but not in the Service Portal. The data is pulling in but it's not filtering the subcategory. I read an article that mentions how some client scripts won't work in the Service Portal and will be addressed in Istanbul Patch 1. However, I need a workaround. The following is the current client scripts I have. Does anyone know a workaround for this issue?

Script 1- Cat/Subcat - onChange-

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

if(newValue == oldValue){

return;

}

//remove all items from subcat drop down to start

// Used the g_form.clearOptions() function instead of g_form.removeOption() function

g_form.clearOptions('subcat');

//build a new list of dependent options

var gp = new GlideRecord('sys_choice');

gp.addQuery('dependent_value', newValue);

gp.addQuery('element', 'subcategory');

gp.query();

while(gp.next()){

  g_form.addOption('subcat', gp.value, gp.label);

}

}

Script 2- Clear out subcat field- onChange

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

// Used the g_form.clearOptions() function instead of g_form.removeOption() function

  if (g_form.getValue('cat') == '') {

  g_form.clearOptions('subcat');

  }

}

pradeepksharma

Any thoughts?

2 REPLIES 2

Michael Fry1
Kilo Patron

Review this thread: Dependent Variables in Service Portal do not reload on values when changed


Two things to remember: Catalog client scripts need both or mobile to work on Portal. The Subcategory lookup box doesn't have a reference to the choice list on Incident: Subcategory table.



Let me know any questions.


Donte Hooker1
Giga Guru
Giga Guru

On the portal the client script has to look a little different. You have use the call back functions. Below I modified the original script by using the call back function. This works on the portal.



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


      if(newValue == oldValue){


              return;


      }


      //remove all items from subcat drop down to start


      // Used the g_form.clearOptions() function instead of g_form.removeOption() function


      g_form.clearOptions('subcategory');


     


      //build a new list of dependent options


      var gp = new GlideRecord('sys_choice');


      gp.addQuery('dependent_value', newValue);


      gp.addQuery('element', 'u_subcategory');


      gp.query(function(gp){


      gp.query();


      while(gp.next())


              g_form.addOption('subcategory', gp.value, gp.label);


      });


}