Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

need to return ci servers in my report

Deepthi13
Tera Expert

 

 i

4 REPLIES 4

Jake Sadler
Kilo Sage

Hello @Deepthi13 ,

 

Try using global.ActiveInactiveABO().getActiveOwnedServers();

 

and in the script return do this:

return activeServers.toString();  // Return the array of server CI identifiers

still not coming
Deepthi13_0-1723021803249.png

var ActiveInactiveABO = Class.create();
ActiveInactiveABO.prototype = {
    initialize: function() {
    },

    getActiveOwnedServers: function() {
        gs.info("first&&&& ");
        var activeServers = [];  // Array to store server CI identifiers
        var gr = new GlideRecord("cmdb_ci_server");
        gr.query();

        while (gr.next()) {
            gs.info("second&&&& ");
            var user = new GlideRecord("sys_user");
            user.addQuery("name", gr.u_abo_application_owner);  // Assuming 'u_abo_application_owner' is a string field
            user.addQuery("active", true);  // Ensure the user is active
            user.query();

            if (user.hasNext()) {  // Check if there is at least one active user
                activeServers.push(gr.getValue("sys_id"));  // Add the server's sys_id to the array
            }
        }
gs.info("&&&& "+activeServers);
return activeServers.toString();  // Return the array of server CI identifiers
     // Return the array of server CI identifiers
    },

    type: 'ActiveInactiveABO'
  1. };

hope this is fine?

 

Is gr.u_abo_application_owner a reference field? If so you may need to use gr.u_abo_application_owner.name or   user.addQuery("sys_id", gr.u_abo_application_owner.sys_id);

 

Do all logs come out? Put one inside the if statement to return the user name

Bhavya11
Kilo Patron
Kilo Patron

Hi @Deepthi13 ,

 

Can you try Client callable script include. it will work.

 

Thanks,

BK