The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Dictionary Override - Reference Qualifier Question

Lucky1
Tera Guru

Hello all,

 

Good day!!

 

On the Incident form, when a configuration item is selected from "Mapped Application Service" (cmdb_ci_service_discovered) class, then only their related Services has to be shown for selection in the "Service" (business_service) field, but not all services. 
For this I have written a Script include, but 

the problem here is, when I open the "Service" field on the dictionary level, I see there is a Dictionary Override, on the Incident. and that is oob one.

javascript:new TaskUtils().getConfigurationItemFilter(current);

 

Now without disturbing the existing functionality, I want to include my script include results also to this reference qualifier, like if(sys_class_name == 'cmdb_ci_service_discovered'), 

 

My Script Include:

var Incident_cmdb_Utils = Class.create();
Incident_cmdb_Utils.prototype = {
    initialize: function() {},

    getServicesForCI: function(ciSysId) {
       // var ciSysId = this.getParameter('sysparm_ci_sysid');
        gs.log("Results are Configuration item sys_id " + ciSysId);
        var serviceIds = [];

        if (!ciSysId) {
            return serviceIds;
        }
        // Step 1: Find offering(s) where child = selected CI (Mapped Application Service)
        var offeringGR = new GlideRecord('cmdb_rel_ci');
        //offeringGR.addQuery('child', ciSysId);
        //offeringGR.addQuery('parent.sys_class_name', 'service_offering');
        offeringGR.addEncodedQuery('parent.sys_class_name=service_offering^child.sys_id=' + ciSysId);
        offeringGR.query();

        while (offeringGR.next()) {

            var offeringId = offeringGR.parent.toString();
            gs.log("Results are Inside 1st While " + offeringId);


            // Step 2: For each offering, get parent services (business or technical)
            var serviceGR = new GlideRecord('cmdb_rel_ci');
            // serviceGR.addQuery('child', offeringId);
            // serviceGR.addQuery('parent.sys_class_name', 'IN', 'cmdb_ci_service_business,cmdb_ci_service_technical');
            serviceGR.addEncodedQuery('parent.sys_class_name=cmdb_ci_service_business^ORparent.sys_class_name=cmdb_ci_service_technical^child.sys_id=' + offeringId);
            serviceGR.query();

            while (serviceGR.next()) {
                //  gs.log("Results are Inside 2nd While");
                serviceIds.push(serviceGR.parent.toString());
                gs.log("Results atLast are " + serviceIds); //some duplicate sys_ids are coming here
            }
        }

        // return serviceIds;
        return JSON.stringify(serviceIds);
    },
    type: 'Incident_cmdb_Utils'
};
 
 
So, can someone please help me here?
 
 
 
Regards,
Lucky
1 REPLY 1

sireesha19
Tera Contributor

On the Incident form, the Service (business_service) field already has a Dictionary Override with the OOB reference qualifier:

javascript:new TaskUtils().getConfigurationItemFilter(current);


You want to restrict services only when the selected Configuration Item (CI) is of class cmdb_ci_service_discovered.
if you directly replace or modify the dictionary override, you risk breaking the OOB behaviour of TaskUtils().getConfigurationItemFilter(current) which is used widely across ITSM.

Try not to remove or overwrite the OOB reference qualifier. Instead, extend it by combining your custom filter logic with the OOB filter.