Populate CMDB CIs based on the Selection of Service Field

Suraj Yadav1
Tera Contributor

Hi Everyone, 

I have a requirement for populating the CIs based on the Service selection.


For example -

If user selects "Service 1", so as per the configuration done in cmdb relationship table (i.e. Service 1 is parent of all the CIs), the specific CIs list should be populated in the CI field.

 

Please suggest me what should be my approach or best practice to take this ahead.

 

Thanks in advance.

5 REPLIES 5

Hi @Suraj Yadav1 

Then I think what you're looking for is Reference Qualifier instead of auto-population. You can also consider autofill if there's only one associated CI as Atul suggested.

 

In your case, if it's just a one-level relationship, we can easily query the cmdb_rel_ci table to retrieve the CIs related to the selected Service, then call the function in the Reference Qualifier of the CI field. Sample:

 

getCIByService: function(service_id){
	var cis = [];
	var grRel = new GlideRecord('cmdb_rel_ci');
	grRel.addQuery('parent', service_id);
	grRel.query();
	while(grRel.next()){
		cis.push(grRel.getValue('child'));
	}
	if(cis.length == 0){
		return 'sys_id=-1'; //empty list
	}else{
		return 'sys_idIN' + cis.join(',');
	}
},

 

 

However, consider a scenario where multi-level relationship exists => CI1, CI2, or CI3 have their own relationships with other CIs. 

You may want to retrieve all related CIs recursively.

 

Cheers,
Tai Vu