Slow fetching of datas in list collector

meghnadash
Tera Contributor

There is requirement where I have to fetch the active catalogs items and return the respective application name in the list collector.

List collector has been running on cmdb_ci_service table and I have to match the data from sc_cat_item_guide_items table.

Here is the onLoad catalog client script where I am calling the script include function

function onLoad() {

  var collectorName = 'app';//Hide the list collector until we've set the filter

  //g_form.setDisplay(collectorName, false);

  setCollectorFilter();

  hideFields();

  displayHelp();

  function getActivesysids()

  {

  var ga = new GlideAjax('ApplicationAccessUtil');

  ga.addParam('sysparm_name','getActiveSysID');

  ga.getXMLWait();

  var test = ga.getXMLAnswer();

  return test;

  }

  function getsysids(response) {

  var answer = response.responseXML.documentElement.getAttribute("answer");

  alert(answer.toString());

  }

  function setCollectorFilter(){

  //Test if the g_filter property is defined on our list collector.

  //If it hasn't rendered yet, wait 100ms and try again.

  if(typeof(window[collectorName + 'g_filter']) == 'undefined'){

  setTimeout(setCollectorFilter, 100);

  return;

  }

  //Reset the filter query

  var filterString = 'name!=NULL^operational_status=27^ORoperational_status=50^sys_id!=6c59ad850a0a3c2501b2a23af58c2b0b^sys_class_name=cmdb_ci_service^u_stop_access_search=false^NQname!=NULL^operational_status=27^ORoperational_status=50^sys_id!=6c59ad850a0a3c2501b2a23af58c2b0b^sys_class_name=u_business_module^u_stop_access_search=false^sys_idIN' + sysids;

  window[collectorName + 'g_filter'].reset();

  window[collectorName + 'g_filter'].setQuery(filterString);

  window[collectorName + 'acRequest'](null);

  //Redisplay the list collector variable

  g_form.setDisplay(collectorName, true);

  g_form.setMandatory(collectorName, true);

  }

}

and the script include part is

getActiveSysID : function ()                                

  {

  var sysids = [];

  var gr = new GlideRecord('sc_cat_item_guide_items');

  gr.addQuery('guide=c27e1d2b543c6c0041059c1972e419b0');

  //gr.addQuery('item.active', 'true');

  gr.query();

  while(gr.next())

  {

  if(gr.item.active == true)

  {

  sysids.push(gr.item.u_application.sys_id);//u_application.name

  }

  }

  gs.log('SYS_IDS' + sysids);

  return sysids;

  },

but it is fetching the wrong name...It is fetching all the CIs.

3 REPLIES 3

Gurpreet07
Mega Sage

If possible, prefer to use reference qual for list collector.


Variable Type Specifications


Harish KM
Kilo Patron
Kilo Patron

I think it shud be


gr.guide.active=true insted of gr.item.active == true


Regards
Harish

Sharique Azim
Mega Sage

Hi Meghna,



I noticed three things in   your code:


1.undefined


hideFields();   displayHelp();



undeclared:


getActivesysids() , which again should be a part of main function or called in the main function.



2.setTimeout(setCollectorFilter, 100); is a very small time ,   you should give it some more time maybe 400 ms..



3.Wrong syntax(please correct me if   i am wrong)


ga.getXML(getsysids) instead of var test = ga.getXMLAnswer();     return test;



Suggestion:



1. You can use sysids.push(gr.getValue('item.u_application')); in your script include


2. return 'sys_idIN'+ sysids.join(','); in your script include


3. Ignore return test; in client script.




Question:


Why are you using script include if   you are   setting the filter from custom string   in client script?