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