How do I configure "System Status Dashboard" in Service Portal

Sahana
Kilo Contributor

Hi Experts,

I am trying to customize the system status dashboard to show outages based on locations

Each Network or Power outage consists Affected location or locations, and I want these locations to show outage legend in the status dashboard.

But I'm unable to display the outage, either all the green legend is being displayed or multiple issues legend is being displayed.

Below is the script I'm trying to customize

(function() {
    data.monthTranslations = {
        'Jan': gs.getMessage("Jan"),
        'Feb': gs.getMessage("Feb"),
        'Mar': gs.getMessage("Mar"),
        'Apr': gs.getMessage("Apr"),
        'May': gs.getMessage("May"),
        'Jun': gs.getMessage("Jun"),
        'Jul': gs.getMessage("Jul"),
        'Aug': gs.getMessage("Aug"),
        'Sep': gs.getMessage("Sep"),
        'Oct': gs.getMessage("Oct"),
        'Nov': gs.getMessage("Nov"),
        'Dec': gs.getMessage("Dec")
    };
    data.categories = [];
    data.locations =[];
    var svs = new GlideRecord("cmn_location");
    svs.setLimit(options.number_of_services || 250);
    svs.orderBy("u_display_name");
    svs.query();
    
    var currentLocation = "-";
    var catIndex = -1;
    data.count = svs.getRowCount();
    while (svs.next()) {
        var gr = new GlideRecord("cmdb_ci_outage");
        gr.addEncodedQuery('u_outage_type=Power^ORu_outage_type=Network');
        gr.query();
        if(gr.next()){
            var cat = svs.getValue("u_locations");
            var    loc = svs.getDisplayValue('u_display_name');
            if (cat != currentLocation) {
                catIndex++;
                currentLocation = cat;
                data.categories[catIndex] = {};
                data.categories[catIndex].name = cat;
                data.categories[catIndex].id = "service_"+catIndex;
                data.categories[catIndex].label = "Locations";
                if (data.categories[catIndex].label == "")
                    data.categories[catIndex].label = gs.getMessage("Service");

                    data.categories[catIndex].services = [];
            }
            var svc = {};
            svc.sys_id = svs.getUniqueValue();
            svc.name = svs.getDisplayValue();
            svc.location = svs.getDisplayValue('u_display_name');
            svc.safeName = GlideStringUtil.escapeHTML(svc.name);
            svc.subscribed = isSubscribed(svc.sys_id);
            var outs = [];
            for (var i = 0; i < 4; i++){
                var out = new GlideAggregate('cmdb_ci_outage');
                out.addEncodedQuery('u_outage_type=Power^ORu_outage_type=Network');
                out.addQuery("end", ">=", gs.daysAgoStart(i)).addOrCondition("end", "");
                out.addQuery("begin", "<=", gs.daysAgoEnd(i));
                out.addAggregate('COUNT', 'type');
                out.query();
                var svcOutageDay = {};
                svcOutageDay.count = 0;
                while (out.next()) {
                    var inc = new GlideRecord('incident');
                    inc.addQuery('sys_id', gr.task_number);
                    inc.query();
                    if(inc.next()){
                        var locArr = [];
                         var locType = inc.u_location_type;
            if (locType == 'single') {
                            locArr.push(inc.u_affected_location);
            } else if (locType == 'multiple') {
                            locArr.push(inc.u_select_locations);
            } else if (locType == 'all') {
                            locArr.push(svs.u_display_name);
            }
                    }
                    var type = out.type;
                    var typeCount = out.getAggregate('COUNT', 'type');
                    gs.addInfoMessage(typeCount);
                    svcOutageDay[type] = typeCount;
                    svcOutageDay.count += typeCount;
                }
                svcOutageDay.icon = "fa-check-circle";
                svcOutageDay.msg = gs.getMessage(" - no outage");
                if (svcOutageDay.count > 1) {
                    svcOutageDay.icon = "fa-plus-circle";
                    svcOutageDay.msg = gs.getMessage("{0} - multiple issues", svc.safeName);
                } else if (svcOutageDay.outage > 0) {
                    svcOutageDay.icon = "fa-exclamation-circle";
                    svcOutageDay.msg = gs.getMessage(" - outage");
                } else if (svcOutageDay.degradation > 0) {
                    svcOutageDay.icon = "fa-minus-circle";
                    svcOutageDay.msg = gs.getMessage("{0} - degradation of service", svc.safeName);
                } else if (svcOutageDay.planned > 0) {
                    svcOutageDay.icon = "fa-info-circle";
                    svcOutageDay.msg = gs.getMessage("{0} - planned maintenance", svc.safeName);
                }
                outs.push(svcOutageDay);
            }
            svc.outages = outs;
            data.categories[catIndex].services.push(svc); //services.
                    if((svc.location != '')){
                data.locations.push(svc.location);
            }            
        }
        }
    data.dates = [];
    for (var i = 5; i > 0; i--) {
        var d = new GlideDate();
        d.subtract(1000 * 3600 * 24 * (i - 1));
        data.dates.push(d.getDisplayValueInternal());
    }

    function isSubscribed(id) {
        var subs = new GlideRecord("m2m_sp_status_subscription");
        subs.addQuery("sys_user", gs.getUserID());
        subs.addQuery("cmdb_ci_service", id);
        subs.query();
        return subs.hasNext();
    }
})();

Any help is much appriciated

Thanks in advance

1 REPLY 1

Community Alums
Not applicable

Hi sahana,

Here is a article by jaspal, should help you :https://community.servicenow.com/community?id=community_blog&sys_id=f413c1dddb0fbf0c190dfb24399619bd

Mark my answer correct & Helpful, if Applicable.

Thanks,
Sandeep