Maintenance plan management - 'next action' scheduling does not work?

deanmpage
Giga Expert

I was just experimenting with the Planned Maintenance app in my personal developer instance, with the intent to implement it in my company's instance for generating Facilities Requests, but I'm having an issue with setting the timing of the first maintenance on Interval triggered schedules.

According to ServiceNow Docs:

Timing the first maintenance

By default, the first planned maintenance is scheduled based on the timing entered in the schedule. For example, if you create a schedule to inspect the air conditioners every six months, the first one occurs six months from schedule creation.

To specify the date of the first maintenance, the administrator can configure the Maintenance Schedule form to include the Next action field. When you create the schedule, select the date you want the first maintenance to be performed.

You can also update this field for any maintenance schedule as needed. For example, if the regular interval is due next month, you can select a date earlier or later in this field to change when the maintenance occurs.

However, this does not seem to work as advertised - adding and updating the Next action field seems to have no effect on the Next run time of the Maintenance Plan Records. Looking at the PlannedMaintenanceUtils Script Include, the only place that I can find the field referenced is in the _addIntervalTriggerData function, where it seems only to be used if the Scheduled Maintenance Plan has run previously, otherwise the next_action field is emptied:

// get next run time

_addIntervalTriggerData: function(scheduleGr, assetGr, newPlanGr) {

// Only Interval durations are calculated based on last run time.

// Scheduled durations should be calculated normally.   The next_action value is

// only used in the interval type glide recurrence

if (newPlanGr.last_run_time.nil()) {

scheduleGr.next_action = "";

} else {

scheduleGr.next_action = newPlanGr.last_run_time;

}

var t = new GlideTime();

t.setDisplayValue(scheduleGr.getDisplayValue('run_time'));

scheduleGr.run_time = t;

var m = GlideARecurrence.get(scheduleGr);

var leadTime = scheduleGr.lead_time;

if (m == null || m.getRowCount() > 0) {

var now = new GlideDateTime();

newPlanGr.setValue('requested_due_by', now);

// Subtract lead time from now. The next run time will be in the past but this if block is an emergency safety net and should never occur.

now.addDaysLocalTime(-leadTime);

newPlanGr.setValue('next_run_time', now);

} else {

var next = m.next();

newPlanGr.setValue('requested_due_by', next);

// Subtract lead time from the next calculated recurrence to get next_run_time.   Note: addDaysLocalTime() is a void function

next.addDaysLocalTime(-leadTime);

newPlanGr.setValue('next_run_time', next);

}

newPlanGr.setValue("next_run_value", ""); // Blank next_run_value incase there is data there

newPlanGr.setValue("last_run_value", ""); // Blank next_run_value incase there is data there

newPlanGr.setValue("field_name", ""); // Blank fieldName incase there is data there

scheduleGr.next_action = ""; // Reset the next action on the schedule in case we are updating schedule

},

Does anyone else have experience with this, and could give me some advice on how to set up Interval-based schedules that start on specified dates?

Thanks & regards,

Dean Page.

1 ACCEPTED SOLUTION

deanmpage
Giga Expert

I've managed to figure this out - it looks like the documentation is incorrect or outdated.



Specifying a next run date is done through the dialog window opened by the Run on demand Related Link UI Action; it's not done by the Next action field.


View solution in original post

4 REPLIES 4

Gilbert Jimenez
ServiceNow Employee
ServiceNow Employee

Hey Dean,



Per my understanding the Next run time should be calculated from the Last completion time not Next Action time.



Can you try updating the Last Completion time and testing again and provide me with your findings?



+Best Regards,


Gilbert


Hi Gilbert,



The Next run time is calculating correctly from the Last completion time when the Maintenance Schedule has run at least once, but that's not the issue I'm having. The issue that I'm having is setting the Next run time for the initial Maintenance Schedule run i.e. when there is no Last completion time.



For example, say I have a Planned Maintenance Schedule that needs to run on an Interval of once every 90 days, and I would like the Maintenance Plans to be actioned for the first time on 1st October 2017. According to ServiceNow Docs, I should be able to put 1st October 2017 in the Next action field, and the Maintenance Plan records should be generated with 1st October 2017 as the Next run time. What actually appears to be happening is that the Next run time is set to current date/time + interval (90 days in this example). Looking at the script, it seems that this is because the Next action field is always being set to empty if there's no Last completion time (see line 06 and 07 of the copied code in my original post).



Any thoughts on this, or am I going to have to modify the PlannedMaintenanceUtils script to achieve what I need?



Regards,


Dean.


deanmpage
Giga Expert

I've managed to figure this out - it looks like the documentation is incorrect or outdated.



Specifying a next run date is done through the dialog window opened by the Run on demand Related Link UI Action; it's not done by the Next action field.


Hi @deanmpage,

Can you help me with my thread related to Planned Maintenance.

https://community.servicenow.com/community?id=community_question&sys_id=cb3c4c75db2abfc01cd8a345ca96...