Service Portal Widget for Planned Outages

YenGar
Mega Sage

Hello all,

I am having an issue with getting a widget that I copied from the Planned Maintenance widget to work in the Service Portal. I am trying to show the current active Outages in the portal based on the Short Description not the CI. We don't have any business services defined in the system so the CI information doesn't show up. Could you please take a look at my code and let me know what I am doing wrong?

All I am trying to do is to populate the short description instead of the CI.

Body HTML template:

<div ng-if="!data.service || data.outages.length > 0" class="panel panel-{{options.color}} b">

  <div class="panel-heading">

      <h4 class="panel-title">${Planned Outages}<span ng-if="data.serviceDisplay"> - {{data.serviceDisplay}}</span></h4>

  </div>

  <div class="panel-body">

  <div ng-if="!data.service">${We publish information on planned service availability below.}</div>

  <div ng-if="data.outages.length == 0" class="col-xs-12 bs-callout bs-callout-success">

  ${No service maintenance is planned over the next 5 days}

  </div>

  <div ng-if="data.outages.length > 0" ng-repeat="outage in data.outages" class="col-xs-12 bs-callout bs-callout-{{outage.type}}">

  <a ng-if="!data.service" style="color:inherit" ng-href="?id=service_status&service={{outage.serviceID}}">${Planned Outage} - {{outage.short_description}}, ${service will be unavailable {{outage.begin}} to {{outage.end}}}</a>

  <span ng-if="data.service" style="color:inherit">${Planned Outage} - {{outage.short_description}}, ${service will be unavailable {{outage.begin}} to {{outage.end}}}</span>

  </div>

  </div>

</div>

Server Script:

// populate the 'data' object

// e.g., data.table = $sp.getValue('table');

var outage = new GlideRecord("cmdb_ci_outage");

outage.addQuery("u_active",true);

//outage.addQuery("begin", "<=", gs.daysAgoStart(-5));

//outage.addQuery("end", ">=", gs.nowNoTZ());

outage.addQuery("type", "Outage Planned");

/*data.service = (input && input.service) || $sp.getParameter("service");

if (!GlideStringUtil.nil(data.service)) {

  outage.addQuery("cmdb_ci", data.service);

  var serviceGR = new GlideRecord("cmdb_ci_service");

  if (serviceGR.get(data.service))

  data.serviceDisplay = serviceGR.getDisplayValue();

}*/

outage.query();

data.outages = [];

data.outageIDs = "";

while (outage.next()) {

  var out = {};

  out.typeDisplay = outage.type.getDisplayValue();

  out.type = outage.getValue("type");

  //out.ci = outage.cmdb_ci.getDisplayValue();

  out.short_description = outage.short_dedscription;

  out.begin = outage.begin.getDisplayValue();

  out.end = outage.end.getDisplayValue();

  //out.serviceID = outage.getValue("cmdb_ci");

  data.outages.push(out);

  data.outageIDs += "," + outage.getUniqueValue();

}

This is how it looks when I go to the page on the portal:

Outages.PNG

Any help is truly appreciated!

Thank you,

Yeny

5 REPLIES 5

Robert Chrystie
ServiceNow Employee
ServiceNow Employee

Hi Yeny,



I don't believe the Outage[cmdb_ci_outage] table has a short description field by default.   I would check if this is a custom field and confirm the name of the field, then update your server script to match.


Hi Robert,



I thought about that but I double checked and the short_description is an OOB field.


short description.PNG


I'm struggling to get it to show up in the widget 😕



Any suggestions you may have are appreciated!



Thank you,


Yeny


Hi Yeny,



Sorry I didn't spot this on my first pass.   It looks like this may just be a syntax error.   You're currently using 'outage.short_dedscription', but based on your screenshot you'd be looking for 'outage.short_description'.   Completely missed this!



Hi Robert,



Oh my!! Just noticed that too! Thank you! I changed it to 'outage.short_description' but it is still giving me the same. The short description is not visible . I think it has something to do with the 'data.service' lines. From what I can see and understand, the data.services is gathering the CI information but we are not using CIs in the outage form since we don't have business services defined to point to.I don't know how to manipulate data.services to work with the short_description field instead of the CI field. Any ideas?



Thank you,


Yeny