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

Charls Brown
Tera Expert

I wanted a script include as the CI field should be based on Location and on business service

 
 
2018 MVP
2016 MVP
2017 Leader (July)
47,368 points - Community Level 8

OK, how are your CIs related to Business Services then?

Charls Brown
Tera Expert

basically its like this:

 

CI’s are tied to an Asset Type. so they added added a reference field called Business Service to the Asset Type record. so  i can walk dot CI to Asset Type to Business Service to get the relationship. 

 

so if user select a location and a business service they should get a CI.

 

 

 

Jim Coyne
Kilo Patron

OK, then the following classless or on-demand function could be used:

Name: u_someCustomFunctionName
Client callable: unchecked
Script:

function u_someCustomFunctionName(businessService, location) {
	//initialize
	var referenceQualifier = [];

	//add the Business Service to the filter if specified
	if (businessService) {
		referenceQualifier.push("u_asset_type.u_business_service=" + businessService);
	}

	//add the Location to the filter if specified
	if (location) {
		referenceQualifier.push("location=" + location);
	}

	gs.addInfoMessage(referenceQualifier.join("^"));  //comment this line out later, just to show you how the filter changes based on what is selected
	return referenceQualifier.join("^");
}

Then use the following "Reference qual":

javascript:u_someCustomFunctionName(current.business_service, current.location);

You could also use the same code but create the Script Include with a class as well.

business services are not directly tied up  to CI.

 

there is a class within cmdb called 'facilities' (sys_class_name) inside that record there is a reference field called assets type and inside that record there is a field called business service.

 

basically for any class different than facilities the Configuration Items should shows the one with the location field. which is working.

but if its facilities (class) then it should show configuration items on the incident form based on location and business service.

 

not really sure if this makes sense to you. but this is the requirement