Reference qualifier for configuration item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2023 04:07 AM
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?
 
 
 
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2023 09:17 AM
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...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2023 08:20 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2023 08:51 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2023 10:01 AM
@Mohith Devatte im getting this but the class and it should be service offering
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-17-2023 05:38 AM
@Mohith Devatte can you please help me to find the solution.
 
Script include:
var IncidentUtil = Class.create();
IncidentUtil.prototype = {
This is what i see when i try to choose CI:
 
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'
};