- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2023 02:16 PM - edited 08-15-2023 02:50 PM
Hello all,
I am a reporting analyst and trying to create a logic to use in a report. Wrote one new function in an already existing script include. I am new to the scripting part and so please can I get help from any to achieve this?
Requirement:
Table - cmdb_ci_service_discovered has application services with different hosting types(u_hosting_type). It also has a reference field called business application name (u_cmdb_ci_business_app) to table cmdb_ci_business_app. It means that a business application can have more than one application service.
Based on the hosting types, I am putting unique count of business application into two buckets (cloud and non-cloud).
Now, I have to get those business applications that fall under both cloud(baCloud) and non-cloud (baNonCloud) buckets. I call it as hybrid application(baHYBRID). Attaching the script I tried here, I am sure it is so amateur, and the logic I used, at last, may be totally wrong for doing it. Can I please get your expertise on this?
// get Hybrid business application with cloud and non cloud hosting type
getBusinessAppsHybrid: function() {
var baHYBRID = [];
var baCloud = [];
var baNonCloud = [];
var ga = new GlideRecord("cmdb_ci_business_app");
ga.addEncodedQuery("install_statusNOT IN3,10,15");
ga.query();
while (ga.next()) {
var gp = new GlideRecord("cmdb_ci_service_discovered");
gp.addEncodedQuery("install_statusNOT IN10,7,15^u_hosting_typeINExternally hosted - Cloud Infrastructure (IAAS/PAAS),Externally hosted – Cloud Infrastructure (IAAS),Externally hosted – Cloud Infrastructure (PAAS),Externally hosted - SAAS^u_cmdb_ci_business_app=" + ga.sys_id);
gp.query();
while (gp.next()) {
baCloud.push(gp.u_cmdb_ci_business_app.sys_id.toString());
if (!gp.next()) {
baNonCloud.push(gp.u_cmdb_ci_business_app.sys_id.toString());
}
}
if (baCloud === baNonCloud){
baHYBRID.push(ga.sys_id.toString());
}
}
return baHYBRID.toString();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2023 04:42 PM
Managed to get the output by modifying above code as like below,
// get Hybrid business applications with cloud and non cloud hosting type
getBusinessApplicationsHybrid: function() {
var busAppsCloud = [];
var busAppsNonCloud = [];
var busApps = new GlideRecord("cmdb_ci_service_discovered");
busApps.addEncodedQuery("install_statusNOT IN10,7,15^u_hosting_typeNOT INExternally hosted - Cloud Infrastructure (IAAS/PAAS),Externally hosted – Cloud Infrastructure (IAAS),Externally hosted – Cloud Infrastructure (PAAS),Externally hosted - SAAS^u_cmdb_ci_business_app.install_statusNOT IN3,10,15");
busApps.query();
while (busApps.next()) {
busAppsNonCloud.push(busApps.u_cmdb_ci_business_app.sys_id.toString());
}
var busApps1 = new GlideRecord("cmdb_ci_service_discovered");
busApps1.addEncodedQuery("install_statusNOT IN10,7,15^u_hosting_typeINExternally hosted - Cloud Infrastructure (IAAS/PAAS),Externally hosted – Cloud Infrastructure (IAAS),Externally hosted – Cloud Infrastructure (PAAS),Externally hosted - SAAS^u_cmdb_ci_business_app.install_statusNOT IN3,10,15");
busApps1.query();
while (busApps1.next()) {
busAppsCloud.push(busApps1.u_cmdb_ci_business_app.sys_id.toString());
}
var busHybrid = getMatch(busAppsNonCloud, busAppsCloud);
function getMatch(a, b) {
var matches = [];
for (var i = 0; i < a.length; i++) {
for (var e = 0; e < b.length; e++) {
if (a[i] === b[e])
matches.push(a[i]);
}
}
return matches;
}
return busHybrid.toString();
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2023 08:34 PM
I hope this helps -
function getBusinessAppsHybrid() {
var baHYBRID = [];
var baCloud = new Set();
var baNonCloud = new Set();
var ga = new GlideRecord("cmdb_ci_business_app");
ga.addEncodedQuery("install_status NOT IN 3, 10, 15");
ga.query();
while (ga.next()) {
var gp = new GlideRecord("cmdb_ci_service_discovered");
gp.addEncodedQuery("install_status NOT IN 10, 7, 15 ^ u_hosting_type IN ('Externally hosted - Cloud Infrastructure (IAAS/PAAS)', 'Externally hosted – Cloud Infrastructure (IAAS)', 'Externally hosted – Cloud Infrastructure (PAAS)', 'Externally hosted - SAAS') ^ u_cmdb_ci_business_app = " + ga.sys_id);
gp.query();
while (gp.next()) {
baCloud.add(gp.u_cmdb_ci_business_app.sys_id.toString());
}
if (baCloud.has(ga.sys_id) && baNonCloud.has(ga.sys_id)) {
baHYBRID.push(ga.sys_id.toString());
}
}
return baHYBRID.toString();
}
Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!
Regards,
Tushar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2023 10:17 PM
Thank you Tushar, I will try this
and update. But, by any chance.. Did you miss to add applications to baNoncloud set.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2023 01:44 AM
Hi Tushar,
It is still not helping. I am still getting no sys id's populated. is there any other way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2023 04:42 PM
Managed to get the output by modifying above code as like below,
// get Hybrid business applications with cloud and non cloud hosting type
getBusinessApplicationsHybrid: function() {
var busAppsCloud = [];
var busAppsNonCloud = [];
var busApps = new GlideRecord("cmdb_ci_service_discovered");
busApps.addEncodedQuery("install_statusNOT IN10,7,15^u_hosting_typeNOT INExternally hosted - Cloud Infrastructure (IAAS/PAAS),Externally hosted – Cloud Infrastructure (IAAS),Externally hosted – Cloud Infrastructure (PAAS),Externally hosted - SAAS^u_cmdb_ci_business_app.install_statusNOT IN3,10,15");
busApps.query();
while (busApps.next()) {
busAppsNonCloud.push(busApps.u_cmdb_ci_business_app.sys_id.toString());
}
var busApps1 = new GlideRecord("cmdb_ci_service_discovered");
busApps1.addEncodedQuery("install_statusNOT IN10,7,15^u_hosting_typeINExternally hosted - Cloud Infrastructure (IAAS/PAAS),Externally hosted – Cloud Infrastructure (IAAS),Externally hosted – Cloud Infrastructure (PAAS),Externally hosted - SAAS^u_cmdb_ci_business_app.install_statusNOT IN3,10,15");
busApps1.query();
while (busApps1.next()) {
busAppsCloud.push(busApps1.u_cmdb_ci_business_app.sys_id.toString());
}
var busHybrid = getMatch(busAppsNonCloud, busAppsCloud);
function getMatch(a, b) {
var matches = [];
for (var i = 0; i < a.length; i++) {
for (var e = 0; e < b.length; e++) {
if (a[i] === b[e])
matches.push(a[i]);
}
}
return matches;
}
return busHybrid.toString();
},