Configuration Item Reference Qualifier Help

cynlink1
Tera Expert

Hello,

 

I have set up a script include to use in the dictionary override for the configuration item on the change request form. While it is working, I can't help but thinking there must be a better way. Any advice would be appreciated.

 

Thanks!

-------------------------------------------------------------

Script:

function ChgRefQualCI() {
return "operational_status!=6^duplicate_ofISEMPTY^sys_class_nameINSTANCEOFcmdb_ci_db_instance^ORsys_class_nameINSTANCEOFcmdb_ci_vm_template^ORsys_class_nameINSTANCEOFcmdb_ci_ec2_instance^ORsys_class_nameINSTANCEOFcmdb_ci_vm_instance^ORsys_class_nameINSTANCEOFcmdb_ci_hardware^ORsys_class_nameINSTANCEOFcmdb_ci_database^ORsys_class_nameINSTANCEOFcmdb_ci_cloud_database^nameISNOTEMPTY^sys_class_name!=cmdb_ci_hardware^ORsys_class_name=^sys_class_name!=cmdb_ci_printer^ORsys_class_name=^ORsys_class_name=cmdb_ci_service_discovered^sys_class_name!=cmdb_ci_computer^ORsys_class_name=^NQsys_class_nameINSTANCEOFcmdb_ci_server^operational_status!=6^duplicate_ofISEMPTY^sys_class_name!=cmdb_ci_db_mssql_catalog^ORsys_class_name=NULL";
}

 

1 ACCEPTED SOLUTION

Ratnakar7
Mega Sage
Mega Sage

Hi @cynlink1 ,

 

It looks like you are using a script include to define a reference qualifier for the Configuration Item field on the Change Request form. While this can work, there are other ways to achieve the same result that might be easier to manage.

One approach is to use the "CI Type" field on the Change Request form to limit the available Configuration Items based on their class. This field is automatically populated based on the class hierarchy of the selected Configuration Item. You can configure the reference qualifier for the Configuration Item field to include this value, like this:

sys_class_nameINjavascript:getCIClasses(current.u_ci_type)

Then, you can create a UI script to populate the "CI Type" field with the appropriate values based on the requirements of your organization. For example, you could use a GlideAjax call to query the cmdb hierarchy and populate the field with a list of all classes that inherit from a particular parent class.

Another approach is to use a dynamic reference qualifier that queries the cmdb hierarchy at runtime to determine the available Configuration Items. This can be more flexible than a static reference qualifier because it adapts to changes in the cmdb hierarchy over time. Here is an example of a dynamic reference qualifier script:

 

 

function getCIQuery() {
  var ciType = current.u_ci_type;
  var ciClasses = [];
  
  // Query the cmdb hierarchy to find all classes that inherit from the selected CI Type
  var gr = new GlideRecord('cmdb_hierarchy');
  gr.addQuery('super_class', ciType);
  gr.query();
  while (gr.next()) {
    ciClasses.push(gr.ci_class.toString());
  }
  
  // Build a query to limit the available CIs to the selected class hierarchy
  var ciQuery = "sys_class_nameIN" + ciClasses.join(',');
  
  return ciQuery;
}

 

 

 

You can configure the reference qualifier for the Configuration Item field to use this script, like this:

javascript:getCIQuery()

This will limit the available Configuration Items based on the class hierarchy of the selected CI Type.

 

 

If my response was helpful in resolving the issue, please consider accepting it as a solution by clicking on the Accept solution button and giving it a thumbs up 👍. This will benefit others who may have a similar question in the future.

 

Thank you!

Ratnakar

View solution in original post

2 REPLIES 2

Ratnakar7
Mega Sage
Mega Sage

Hi @cynlink1 ,

 

It looks like you are using a script include to define a reference qualifier for the Configuration Item field on the Change Request form. While this can work, there are other ways to achieve the same result that might be easier to manage.

One approach is to use the "CI Type" field on the Change Request form to limit the available Configuration Items based on their class. This field is automatically populated based on the class hierarchy of the selected Configuration Item. You can configure the reference qualifier for the Configuration Item field to include this value, like this:

sys_class_nameINjavascript:getCIClasses(current.u_ci_type)

Then, you can create a UI script to populate the "CI Type" field with the appropriate values based on the requirements of your organization. For example, you could use a GlideAjax call to query the cmdb hierarchy and populate the field with a list of all classes that inherit from a particular parent class.

Another approach is to use a dynamic reference qualifier that queries the cmdb hierarchy at runtime to determine the available Configuration Items. This can be more flexible than a static reference qualifier because it adapts to changes in the cmdb hierarchy over time. Here is an example of a dynamic reference qualifier script:

 

 

function getCIQuery() {
  var ciType = current.u_ci_type;
  var ciClasses = [];
  
  // Query the cmdb hierarchy to find all classes that inherit from the selected CI Type
  var gr = new GlideRecord('cmdb_hierarchy');
  gr.addQuery('super_class', ciType);
  gr.query();
  while (gr.next()) {
    ciClasses.push(gr.ci_class.toString());
  }
  
  // Build a query to limit the available CIs to the selected class hierarchy
  var ciQuery = "sys_class_nameIN" + ciClasses.join(',');
  
  return ciQuery;
}

 

 

 

You can configure the reference qualifier for the Configuration Item field to use this script, like this:

javascript:getCIQuery()

This will limit the available Configuration Items based on the class hierarchy of the selected CI Type.

 

 

If my response was helpful in resolving the issue, please consider accepting it as a solution by clicking on the Accept solution button and giving it a thumbs up 👍. This will benefit others who may have a similar question in the future.

 

Thank you!

Ratnakar

Thank you for your response Ratnakar!