CI based on location
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2018 07:53 AM
Hello,
I want to bring all the CI´s based on location. On the incident form if a user select a location then all CI´s need to be filtered by that specific location. I have created a script include and I am calling with a reference qualifier on the Configuration Item field but for some reason its not working:
client callable
script include
var SevenEleven_CI_ReferenceQuali = Class.create();
SevenEleven_CI_ReferenceQuali.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getConfigurationItems: function(ci_id) {
// if (!ci_id)
// return;
gs.log("Business Service ID: " + ci_id);
// Set up return value
var returnList = '';
// Get the Category Structures
var ci_gr = new GlideRecord('cmdb_ci');
ci_gr.addQuery('location', ci_id);
ci_gr.query();
while (ci_gr.next()) {
if (returnList == '') {
returnList += ci_gr.location.sys_id;
} else {
returnList += ',' + ci_gr.location.sys_id;
}
}
// gs.log("Return List: " + returnList);
// Return the values
return returnList;
},
type: 'SevenEleven_CI_ReferenceQuali'
});
Reference qualifier:
javascript:new SevenEleven_CI_ReferenceQuali().getConfigurationItems(current.location);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2018 08:00 AM
I think you have to find CIs with location but first query compares location to ci_id
Provided you pass sys_id of CI here.
var SevenEleven_CI_ReferenceQuali = Class.create();
SevenEleven_CI_ReferenceQuali.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getConfigurationItems: function(ci_id) {
// if (!ci_id)
// return;
gs.log("Business Service ID: " + ci_id);
// Set up return value
var returnList = ' ';
// Get the Category Structures
var ci_gr = new GlideRecord('cmdb_ci');
ci_gr.addQuery('sys_id', ci_id);
ci_gr.query();
while (ci_gr.next()) {
if (returnList == '') {
returnList += ci_gr.location.sys_id;
} else {
returnList += ',' + ci_gr.location.sys_id;
}
}
// gs.log("Return List: " + returnList);
// Return the values
return returnList;
},
type: 'SevenEleven_CI_ReferenceQuali'
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2018 08:09 AM
In case you pass sys_id of location to your script please use this version.
So you return CIs ids not locations.
var SevenEleven_CI_ReferenceQuali = Class.create();
SevenEleven_CI_ReferenceQuali.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getConfigurationItems: function(ci_id) {
//gs.log("Business Service ID: " + ci_id);
// Set up return value
var returnList = ' ';
// Get the Category Structures
var ci_gr = new GlideRecord('cmdb_ci');
ci_gr.addQuery('location', ci_id);
ci_gr.query();
while (ci_gr.next()) {
if (returnList == ' ') {
returnList += ci_gr.sys_id;
} else {
returnList += ',' + ci_gr.sys_id;
}
}
//gs.log("Return List: " + returnList);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2018 10:53 AM
it doesnt work

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2018 11:48 AM
I've tested this approach on my server and when location is passed it gives a list of CIs.
Check if you passing really sys_id of location to script.
var ci_id='f9f5a7d46fc965002c2adece5d3ee426';
gs.log("Business Service ID: " + ci_id);
// Set up return value
var returnList = ' ';
// Get the Category Structures
var ci_gr = new GlideRecord('cmdb_ci');
ci_gr.addQuery('location', ci_id);
ci_gr.query();
while (ci_gr.next()) {
if (returnList == ' ') {
returnList += ci_gr.sys_id;
} else {
returnList += ',' + ci_gr.sys_id;
}
}
gs.log("Return List: " + returnList);