None in Catalog Client Script After clearOption()

SNOW User8
Giga Guru

Hi Experts,

I am trying to dynamically get "Subcategory" based on "Category" from incident table using catalog client script for Service Portal.

Every time category changes the subcategory getting populated normally. No issues.

But the issue is that getting --None-- value only by the first time category change.

Please find my script below,

Name: Catalog Client Script

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

if(newValue == ''"){

  g_form.clearOptions('subcategory');

  g_form.clearOptions('u_subcategory_2');

  }

if(newValue == oldValue){

  return;

  }

  g_form.clearOptions('subcategory');

  g_form.addOption('subcategory', 'none', '-- None --',0);

  g_form.setValue('subcategory', 'none',   '-- None --');

  var gp = new GlideRecord('sys_choice');      

  gp.addQuery('name', 'incident');      

  gp.addQuery('dependent_value', newValue);      

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

  gp.addQuery('inactive', 'false');      

  gp.query(function(gp) {

  while(gp.next()){

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

  }

  g_form.addOption('subcategory', 'none', '-- None --',0);

  g_form.setValue('subcategory', 'none',   '-- None --');

   

  });    

}

Please help me to solve the issue.

Thanks in Advance.

Regards,

Anna.

17 REPLIES 17

akaupisch
Kilo Guru

One other thing to keep in mind that some people miss. Client Catalog Scripts require UI Type = ALL to work in the Service Portal. If you have it setup for desktop only, it won't execute on the service portal. I suspect you probably have it on all.


Hi Adam Kaupisch,



Thanks for your response.



I am keeping it as "Both" only.


And I have tried the Scripts which you have shared.


But still facing the same issue.



Regards,


Anna.



Hi Anna,



Can you share a screenshot of your form?



Do you have the Choice as Drop down with --None-- selected in the variables you are using?



Please mark this response as correct or helpful if it assisted you with your question.

Hi Sanjiv,



Please   find the screenshot below,



find_real_file.png






Regards,


Anna.


Sorry. The form where you dont see -None-



Please mark this response as correct or helpful if it assisted you with your question.