scripted report: script include function

Raja keerthana
Kilo Guru

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

Rajakeerthana_0-1692136184938.png

 

 

1 ACCEPTED SOLUTION

Raja keerthana
Kilo Guru

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();
},

View solution in original post

4 REPLIES 4

Tushar
Kilo Sage
Kilo Sage

Hi @Raja keerthana 

 

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

Thank you Tushar, I will try this 

and update. But, by any chance.. Did you miss to add applications to baNoncloud set. 

Hi Tushar, 

It is still not helping. I am still getting no sys id's populated. is there any other way.

Raja keerthana
Kilo Guru

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();
},