Slow performance reference qualifier script include

rai5
Mega Guru

Hello Devs,

I had to use a script include on a reference qualifier for the configuration item field on the task table due to limitations with the condition builder. The condition builder does not allow me to use as many filters and conditions as I need. The script include works fine but it is painfully slow. Is there a way to improve performance in this situation. I would imagine this is a very common challenge but I was not able to find anything while researching online.

here is the logic of the script. Feel free to suggest a better way.

 

function returncis() {
 
var objs = [];
var equery
= "sys_class_nameINcmdb_ci_computer,cmdb_ci_printer,cmdb_ci_ip_firewall,cmdb_ci_ip_router,cmdb_ci_ip_switch,cmdb_ci_wan_accel_network,cmdb_ci_ups,cmdb_ci_ucs_equipment,cmdb_ci_lb_netscaler,cmdb_ci_win_server,cmdb_ci_linux_server,cmdb_ci_solaris_server,cmdb_ci_unix_server,cmdb_ci_aix_server,cmdb_ci_storage_switch,cmdb_ci_db_mssql_instance,cmdb_ci_db_ora_instance^install_status!=7^discovery_sourceINManual Entry,ServiceNow,SolarWinds^EQ";
  
  var ci = new GlideRecord('cmdb_ci');
  ci.addEncodedQuery(equery);
  ci.query();
     while(ci.next()) {
   
    objs.push(ci.getValue('sys_id'));
   
   }
  return 'sys_idIN' +  objs.join(',');
}

 

 

1 ACCEPTED SOLUTION

Jon Barnes
Kilo Sage

So the problem is that you are adding an extra query to the cmdb_ci table that you don't actually need. instead of what you have, can you try it with this function:

 

function returncis() {
  return "sys_class_nameINcmdb_ci_computer,cmdb_ci_printer,cmdb_ci_ip_firewall,cmdb_ci_ip_router,cmdb_ci_ip_switch,cmdb_ci_wan_accel_network,cmdb_ci_ups,cmdb_ci_ucs_equipment,cmdb_ci_lb_netscaler,cmdb_ci_win_server,cmdb_ci_linux_server,cmdb_ci_solaris_server,cmdb_ci_unix_server,cmdb_ci_aix_server,cmdb_ci_storage_switch,cmdb_ci_db_mssql_instance,cmdb_ci_db_ora_instance^install_status!=7^discovery_sourceINManual Entry,ServiceNow,SolarWinds^EQ";
}

 

In fact, you can just put that string qualifier directly in the Advanced Ref Qualifier box on the task.cmdb_ci dictionary entry and don't really need the script include at all. like this:

 

find_real_file.png

View solution in original post

8 REPLIES 8

rai5
Mega Guru

Thanks for your reply Sanjivmeher,

This is something I have tried but did not work because the filter does not take so many conditions, it gets truncated; therefore the need for the script include.

I think you can make the query more efficient. Instead of querying each class you can query their master class. For ex you can just query cmdb_ci_server instead of cmdb_ci_win_server, unix, aix etc which should reduce the length. Also cmdb_ci_instance instead of mssql and ora

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

rai5
Mega Guru

Jon,

I will try that and report back. Thanks!

rai5
Mega Guru

Thanks Jon

Well, Jon's solution worked really well. I had to use it in the script include because the filter would not allow me to add so many conditions using simple filter. Thanks everyone!