Reference qualifier for configuration item

Alon Grod
Tera Expert

Hi, i have the fields Configuration item and Service offering on the incident table.

The configuration item need to show only CI's that related to the Service offering that has been chosen.

I need to use the cmdb_rel_ci table and whenever someone wants to choose a CI, he will only see the CI's that their 'parent' in the cmdb_rel_ci table is the Service offering that was chosen.

For some reason I still see the full list of CI's, what am I doing wrong?

 

Screen Shot 2023-01-16 at 14.06.15.png

 

Screen Shot 2023-01-16 at 14.06.37.png

 

Screen Shot 2023-01-16 at 14.07.33.png

 

14 REPLIES 14

That looks right now.  This is working in my PDI.  Make sure you don't have more than one Script Include named IncidentUtils.  If you do, change the new one and the reference qualifier, or just add the new function to the original SI.  You can add some logging lines to the SI to confirm that it is running, and to see what's happening throughout the script.

var IncidentUtils = Class.create();
IncidentUtils.prototype = {
	
    getCis: function(so) {    
        gs.addInfoMessage('SI running - SO = ' + so) 
		var getCiArr = [];
        if (so) {
            gs.addInfoMessage('SI inside if')
            var gr = new GlideRecord('cmdb_rel_ci');
            gr.addQuery('parent', so);
            gr.query();
            while (gr.next()) {
                gs.addInfoMessage('inside while')
                getCiArr.push(gr.child.sys_id.toString());
            }
            gs.addInfoMessage('array = ' + getCiArr.join(',')
            return "sys_idIN" + getCiArr.join(',');
        }
    },

    type: 'IncidentUtils'
};

When you click the reference search icon on the CI field you should see the blue info messages...

Mohith Devatte
Tera Sage
Tera Sage

Hello @Alon Grod can you try this ?

var IncidentUtils = Class.create();
IncidentUtils.prototype = {
	
    getCis: function(so) {     
		var getCiArr = [];
        if (so) {
      var cm = new GlideRecord('cmdb_ci');
  cm.addEncodedQuery('sys_class_name=service_offering');
cm.addQuery('sys_id',so);
cm.query();
if(cm.next())
{
            var gr = new GlideRecord('cmdb_rel_ci');
            gr.addQuery('parent',cm.sys_id);
            gr.query();
            while (gr.next()) {
                getCiArr.push(gr.child.sys_id.toString());
            }
            return "sys_idIN" + getCiArr.join(',');
        }
}
    },

    type: 'IncidentUtils'
};

Hope this helps 

Mark my answer correct if this helps you 

Thanks

@Mohith Devatte unfeortennaly still not working. This is what i have now:

 

Screen Shot 2023-01-16 at 18.50.43.png

 

Screen Shot 2023-01-16 at 18.51.22.png

 

@Mohith Devatte  im getting this but the class and it should be service offering

Screen Shot 2023-01-16 at 20.00.39.png

@Mohith Devatte can you please help me to find the solution.

Screen Shot 2023-01-17 at 15.35.36.png

 

Script include:

var IncidentUtil = Class.create();
IncidentUtil.prototype = {

 

This is what i see when i try to choose CI:

Screen Shot 2023-01-17 at 15.38.00.png

 


getCis: function(so) {
var getCiArr = [];
if (so) {
var cm = new GlideRecord('cmdb_ci');
cm.addEncodedQuery('sys_class_name=service_offering');
cm.addQuery('sys_id',so);
cm.query();
if(cm.next())
{
var gr = new GlideRecord('cmdb_rel_ci');
gr.addQuery('parent',cm.sys_id);
gr.query();
while (gr.next()) {
getCiArr.push(gr.child.sys_id.toString());
}
return "sys_idIN" + getCiArr.join(',');
}
}
},

type: 'IncidentUtil'
};