list databases related with all the mapped application services for the selected business applicatio

dharshinir2
Tera Contributor

How to list databases related with all the mapped application services for the selected business applications with script include using reference qualifier in a catalog item

2 REPLIES 2

Shubham_Jain
Mega Sage


@dharshinir2 

Step 1: 

 

var GetDatabasesForBusinessApp = Class.create();
GetDatabasesForBusinessApp.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDatabases: function() {
var businessAppId = this.getParameter('sysparm_business_app');
var dbIds = [];

// Find all Application Services related to the Business App
var relGR = new GlideRecord('cmdb_rel_ci');
relGR.addQuery('parent', businessAppId); // assuming parent is Business App
relGR.addQuery('type.name', 'Depends on::Used by');
relGR.query();

var serviceIds = [];
while (relGR.next()) {
serviceIds.push(relGR.child.sys_id.toString());
}

if (serviceIds.length > 0) {
// Find all related Databases from those services
var relDB = new GlideRecord('cmdb_rel_ci');
relDB.addQuery('parent', 'IN', serviceIds);
relDB.addQuery('type.name', 'Depends on::Used by');
relDB.addQuery('child.sys_class_name', 'cmdb_ci_database');
relDB.query();

while (relDB.next()) {
dbIds.push(relDB.child.sys_id.toString());
}
}

return dbIds.join(',');
}
});

 

Note: make sure script include is client callable 

 

step 2: 

Reference Qualifier: 

 

javascript: 'sys_idIN' + new GetDatabasesForBusinessApp().getDatabases(current.variables.business_application);

 

 

 

✔️ If this solves your issue, please mark it as Correct.


✔️ If you found it helpful, please mark it as Helpful.



Shubham Jain


Hi @Shubham_Jain 

      It is not working still, how to proceed further. It is showing as 'no matches found '