Reference qualifier on CI in Record Producer

Pratiksha KC
Tera Guru

We wants to achieve reference qualifier for configuration Item variable based on two conditions: 

 

1. if category selected as software it should show the records from table - cmdb_ci_service_discovered and cmdb_ci_service_auto. 

 

(For this we have wrote advance qualifier , it is working fine -
javascript:current.variables.category=='software' ? 'sys_class_name=cmdb_ci_service_discovered^ORsys_class_name=cmdb_ci_service_auto' : '' ) 

 


2. The field CI on the RRP should only show records from Primary classes.

In backend, on incident we have reference qualifier For CI - javascript: ['incident', 'problem'].indexOf(current.sys_class_name + '') == -1? '' : 'operational_statusNOT IN' + new OpsStatusFilter('cmdb_ci').by('CreateTask').join()

 

How can we achieve this?

PratikshaKC_0-1749660882433.png

 

1 ACCEPTED SOLUTION

Pratiksha KC
Tera Guru

Got the solution - 

javascript:current.variables.category == 'software' ? 'sys_class_name=cmdb_ci_service_discovered^ORsys_class_name=cmdb_ci_service_auto' : new TaskUtils().getConfigurationItemFilter({sys_class_name : 'incident'})

View solution in original post

17 REPLIES 17

Hi we have second condition as if category is not software than CI should show principle classes CI's 

 

We already have script include in system that we are using for CI on Incident form. 

SI -

var OpsStatusFilter = Class.create();
OpsStatusFilter.prototype = {
    initialize: function(ciType) {
        this.ciType = ciType;
    },
   
    by: function (actionName) {
        var gr = new GlideRecord('statemgmt_not_allow_actions');
        gr.addQuery('ci_type', this.ciType);
        gr.addQuery('not_allowed_action.name', actionName);
        gr.query();
        var ops = [];
        while (gr.next()) {
            ops.push(gr.operational_state + '');
        }
       
        return ops;
    },
   
    type: 'OpsStatusFilter'
};
 
Calling this SI in Reference Qualifier of CI - 
javascript: ['incident', 'problem'].indexOf(current.sys_class_name + '') == -1? '' : 'operational_statusNOT IN' + new OpsStatusFilter('cmdb_ci').by('CreateTask').join()
 
But we wants to use same functionality in record producer's variable CI 

Hi @Pratiksha KC ,

you can put the script I have shared in the refence qualifier

this script include OpsStatusFilter.by method is only returns operational status of CIs which should not be available for selection that's it. it has nothing to do with principal classes

 

principle class ci are the classes of cis 

to find principal class you can go to table cmdb_class_info table and find where principal class is true

ChaitanyaILCR_0-1749740935117.png

 

I have tested this script and is working try this

javascript:(function() {
    if (current.variables.category == 'software')
        return 'sys_class_name=cmdb_ci_service_discovered^ORsys_class_name=cmdb_ci_service_auto';

    var cciGr = new GlideRecord("cmdb_class_info");
    cciGr.addEncodedQuery("principal_class=true");
    cciGr.query();
    var clssArr = [];
    while (cciGr.next()) {
        clssArr.push(cciGr.getValue('class'));
    }

    return '^operational_statusNOT IN' + new OpsStatusFilter('cmdb_ci').by('CreateTask').join() + (clssArr.length ? '^sys_class_nameIN' + clssArr.join() : '');

})();

ChaitanyaILCR_1-1749741544709.png

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

 

 

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Pratiksha KC 

so the 1st requirement is done

what's the 2nd one?

are you saying if it's software then 1st filter and if not software then the 2nd filter should come as per INC ref qualifier?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar 

 

Yes, if category is not software , it should show records from Primary classes.

(As same RQ as we have in backend for incident : javascript: ['incident', 'problem'].indexOf(current.sys_class_name + '') == -1? '' : 'operational_statusNOT IN' + new OpsStatusFilter('cmdb_ci').by('CreateTask').join() )

 

Also we are facing issue with CI variable showing duplicate CIs.

 

we wants to restrict duplicate CI's name from the Configuration item. 

@Pratiksha KC 

this line simply gives you the choice value for operational status

why not use directly?

var val = new OpsStatusFilter('cmdb_ci').by('CreateTask').join();
gs.info(val);

This prints 6 which is the choice value for operational status field

So update your advanced ref qualifier as this

javascript: var query; if(current.variables.category == 'software') query = 'sys_class_name=cmdb_ci_service_discovered^ORsys_class_name=cmdb_ci_service_auto'; else query = 'operational_statusNOT IN6'; query; 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader