Repeat schedule entry span on timeline

Fredrik v S
Mega Guru

Hello,

I'm currently working on creating a timeline view over upcoming change requests, however I'd also like to add maintenance and blackout schedules into the same view.

Change Schedule.PNG

I have created a script include that shows the upcoming change requests and groups them based on their workflow stage (u_wf_stage). I seem to be unable to add the blackout and maintenance schedules into this timeline view, it works in the calendar view using schedule.addpage but that's not what I'm looking for. I'm curious as to how I'm supposed to be able to create a span from a cmn_schedule entry.

This is the particular part I can't get to work:

  var g = new GlideRecord('cmn_schedule');

  g.initialize();

  g.addQuery('type', 'blackout');

  g.query();

  while (g.next()) {

  var item1 = new GlideTimelineItem(g.getTableName(), g.sys_id);

  var span1 = item1.createTimelineSpan(g.getTableName(), g.sys_id);

  item1.setParent(groupBlackout.getSysId());

  item1.setLeftLabelText(g.name);

  // span1.setTimeSpan(g.getElement('start_date_time').getGlideObject().getNumericValue(), gr.getElement('end_date_time').getGlideObject().getNumericValue());

  // schedulePage.addSchedule(g.sys_id, '#000', null, true);

  this.add(item1);

  }

  g.initialize();

  g.addQuery('type', 'maintenance');

  g.query();

  while (g.next()) {

  var item2 = new GlideTimelineItem(g.getTableName(), g.sys_id);

  var span2 = item2.createTimelineSpan(g.getTableName(), g.sys_id);

  item2.setParent(groupMaintenance.getSysId());

  item2.setLeftLabelText(g.name);

  // schedulePage.addSchedule(g.sys_id, '#e9ff00', null, true);

  this.add(item2);

Now the queries return and group then where they ought to be, as intended by setParent

However, I am unable to get it to draw the values returned in the timeline, because I can't draw a span based on what's returned to me using (because of how schedules are calculated in Service Now):

span1.setTimeSpan(g.getElement('start_date_time').getGlideObject().getNumericValue(), g.getElement('end_date_time').getGlideObject().getNumericValue());

Has anyone been able to resolve an issue similar to this one while stil using the OOB-function for schedules and in this particular case maintenance windows and blackout windows?

5 REPLIES 5

stevemac
Tera Guru

thank you very much for this.  Saved me a ton of time

My use case https://community.servicenow.com/community?id=community_question&sys_id=4cda502edbf2b344190dfb243996...