The CreatorCon Call for Content is officially open! Get started here.

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
10 REPLIES 10

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. 


Yes Sireesha,

 

I have understood that.

So, I am thinking to write the logic, something like this,

In my script include, I will write like, if configuration item class is Mapped APplication Service, then my logic will fire, 

else,

I will call the existing oob script include.

 

This will work right?

 

 

Regards,

Lucky

Yes that should work do what you need to do is create a new SI and write your logic for mapped app class and return, if no then call the oob script include from your SI.

 

You can do the same thing by overriding the OOB as well. Its your choice to either override or create new SI


Raghav
MVP 2023
LinkedIn

Hello Raghav,

 

That oob Script include is Read-only. And frank to speak I am not aware how to override the oob Script include for my logic.

 

If possible, please let me know how to do that?

Meanwhile I will write my logic. (Already my Script include pasted in the question).

 

 

Regards,

Lucky