Reference qualifier for model_id is returning models with no category

GLewis5
Tera Guru

Can anyone explain to me the reason for these two lines which appear in the Script Include ModelAndCategoryFilters?

 // when creating a CI, we always allow models with no category
var refQual = 'cmdb_model_categoryISEMPTY';

Our problem is that we are starting to use CI classes which we have not used before. There are a huge number of product models that were defined in the past with no model categories. This was not an issue in the past, because we were not creating these CI's manually. Now we are starting to create new classes of CIs manually, and the reference qualifier is returning completely inappropriate results.

1 ACCEPTED SOLUTION

GLewis5
Tera Guru

If, like me, you want to change this behavior of ModelAndCategoryFilters, then here is Script Include that will do it:

var ModelAndCategoryFiltersCustom = Class.create();
ModelAndCategoryFiltersCustom.prototype = Object.extendsObject(ModelAndCategoryFilters, {
    /*
     * Custom version of reference qualifier excludes models with no category 
     * (unless there are no other models available).
     */	
    ciModelRefQual: function(ci) {
        var refQual;
        var ciClass = this._getCIClass(ci);
        var category = new GlideRecord('cmdb_model_category');
        category.addQuery('cmdb_ci_class', ciClass);
        category.query();
        if (category.next())
            refQual = 'cmdb_model_categoryLIKE' + category.sys_id;
        else
            refQual = 'cmdb_model_categoryISEMPTY';
        return refQual;
    },
	
    type: 'ModelAndCategoryFiltersCustom'
});

Next you need to change the Reference Qualifier. The default Reference Qualifier for model_id is in the Dynamic Filter Option "CI Model Qualifier". You can either change it there (if you want it to affect all CI classes), or create a Reference Qualifier Dictionary Entry Override for specific CI classes. The new Reference Qualifier is

new ModelAndCategoryFiltersCustom().ciModelRefQual(current)

 

View solution in original post

2 REPLIES 2

rrataj
Kilo Expert

Hi, 

if we are speaking about CI's then the refQual is 

javascript:new ModelAndCategoryFilters().ciModelRefQual(current)

 

https://instnace.service-now.com/nav_to.do?uri=sys_script_include.do?sys_id=d1816da63703100044e0bfc8bcbe5d61

 

	/*
     * Configuration Item model reference
     */
	ciModelRefQual: function(ci) {
	    // when creating a CI, we always allow models with no category
		var refQual = 'cmdb_model_categoryISEMPTY';
	   
	    // add an OR filter to get only the models that match the class of CI we are creating
	    var ciClass = this._getCIClass(ci);		
		var category = new GlideRecord('cmdb_model_category');
		category.addQuery('cmdb_ci_class', ciClass);
		category.query();
	    if (category.next())
		    refQual += '^ORcmdb_model_categoryLIKE' + category.sys_id; 
	   
	    return refQual;
    },

 

in the end you get

refQual = 'cmdb_model_categoryISEMPTY^ORcmdb_model_categoryLIKE' + category.sys_id; 

 

so seems you have messy data on model category for the current CI class 

GLewis5
Tera Guru

If, like me, you want to change this behavior of ModelAndCategoryFilters, then here is Script Include that will do it:

var ModelAndCategoryFiltersCustom = Class.create();
ModelAndCategoryFiltersCustom.prototype = Object.extendsObject(ModelAndCategoryFilters, {
    /*
     * Custom version of reference qualifier excludes models with no category 
     * (unless there are no other models available).
     */	
    ciModelRefQual: function(ci) {
        var refQual;
        var ciClass = this._getCIClass(ci);
        var category = new GlideRecord('cmdb_model_category');
        category.addQuery('cmdb_ci_class', ciClass);
        category.query();
        if (category.next())
            refQual = 'cmdb_model_categoryLIKE' + category.sys_id;
        else
            refQual = 'cmdb_model_categoryISEMPTY';
        return refQual;
    },
	
    type: 'ModelAndCategoryFiltersCustom'
});

Next you need to change the Reference Qualifier. The default Reference Qualifier for model_id is in the Dynamic Filter Option "CI Model Qualifier". You can either change it there (if you want it to affect all CI classes), or create a Reference Qualifier Dictionary Entry Override for specific CI classes. The new Reference Qualifier is

new ModelAndCategoryFiltersCustom().ciModelRefQual(current)