CI based on location

Charls Brown
Tera Expert

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);

24 REPLIES 24

I need it with a script include.

Why is that?

this works fine for me. Thank you Jim.

You are welcome.  Remember to mark any response as being helpful.  Thanks.

Jim Coyne
Kilo Patron

There are a number of ways to handle this:

1. A simple "Advanced" Reference Qualifier

Set the "Use reference qualifier" to "Advanced" and set the "Reference qual" field to "javascript:"location=" + current.location;"

find_real_file.png

This is really the simplest way of doing it.

 

2. A classless Script Include Function

Set the "Use reference qualifier" to "Advanced" and set the "Reference qual" field to "javascript:u_someCustomFunctionName(current.location);"

Then create a Script Include with the following details:

Name: u_someCustomFunctionName
Client callable: unchecked
Script:

function u_someCustomFunctionName(location) {
	return "location=" + location;
}

find_real_file.png

Simple, but the first one is simpler.

 

3. Class-based Script Include

Set the "Use reference qualifier" to "Advanced" and set the "Reference qual" field to "javascript:new SevenEleven_CI_ReferenceQuali().getConfigurationItems(current.location);"

Then create a Script Include with the following details:

Name: SevenEleven_CI_ReferenceQuali
Client callable: unchecked
Script:

var SevenEleven_CI_ReferenceQuali = Class.create();
SevenEleven_CI_ReferenceQuali.prototype = {
    initialize: function() {
    },

	getConfigurationItems: function(location) {
		return "location=" + location;
	},
	
    type: 'SevenEleven_CI_ReferenceQuali'
};

find_real_file.png

 

The big problem with the answers above is that only the sys_ids were being returned and NOT the entire filter (e.g. sys_id=list of ids).  The platform did not  know what you wanted to do with the list.