Oscar Lopez
Mega Guru
Mega Guru

When implementing Change Management you're always going to need to calculate Lead Time for a Change to be implemented.

Lead Time means how much time (in terms of days) are in advance before a Change can be implemented.

Key factors are Planned Start Date, Priority and Change Type. Depending on customer requirements and change management process there will be other factors to consider but for now let's focus on how to calculate lead time.

find_real_file.png

The Formula

Here is an example on how to calculate the Lead Time.

var changePlannedStartDate = "2020-03-29 15:00:00";
var date1 = new GlideDateTime(changePlannedStartDate);
var date2 = new GlideDateTime(gs.nowDateTime());

// ge the difference in terms of number of days elapse between two dates
// returns days in format: ddd hh:mm:ss
var diff = gs.dateDiff(date1.getDisplayValue(), date2.getDisplayValue(), false);
// obtains only number of days
// if diff has a length of 8 characters then it's only hours difference meaning 0 days lead time
var daysDiff = diff.length == 8 ? 0 : parseInt(diff.slice(0,-8));
		
// make it a positive number
if(daysDiff < 0) daysDiff = -1 * daysDiff;

 

Now with the Lead Time calculated you may do different things:

  • Display a custom message in the Change form to let know the requester that there's no sufficient lead time to continue with the planned schedule.
  • You may automatically change the type of the Change; say for example from Normal to Emergency
  • Perhaps additional approvals are needed for so short notice.

 

Oscar Lopez

@oslovanet

 

Comments
Jan Sierens1
Tera Contributor

Hi Oscar,

It is good practice to check the lead time depending on the change type to very if the lead time is within limits for the request type. But automatically changing the type of change from Normal to Emergency is not a good idea. Customers I know who requested an automatic change, came back on their decision. 

Best regards,

Jan

Samartha Shetty
Tera Expert
This Code works in business rule for normal change, and condition shoul be after and planned start is no empty
(function executeRule(current, previous /*null when async*/ ) {

    var startDate = current.sys_created_on;
    var endDate = current.start_date;
    var stat = current.state;
    var ris = current.risk;
    var typ=current.type;
    var r = '';

    var newStartDate = new GlideDateTime(startDate);

    if (ris == 1 && typ=='normal') {
        newStartDate.addDays(21);
        r = "Very High Risk";
    } else if (ris == 2 && typ=='normal') {
        newStartDate.addDays(14);
        r = "High Risk";
    } else if (ris == 3 && typ=='normal') {
        newStartDate.addDays(7);
        r = "Moderate";
    } else if (ris == 4 && typ=='normal') {
        newStartDate.addDays(2);
        r = "Low Risk";
    } else if (ris == 5 && typ=='normal') {
        newStartDate.addDays(2);
        r = "No Risk";
    }



    //gs.addInfoMessage('errror');
   // gs.addInfoMessage(newStartDate + 'stat' + stat + " risk:" + ris+" type "+typ);

    if (newStartDate > endDate) {
        gs.addErrorMessage('lead time errror');
        gs.addErrorMessage('Planned Start Date Should be after ' + newStartDate + " for Normal Change With "+r);
        gs.state=stat;
        gs.update();

    }

})(current, previous);
Samartha Shetty
Tera Expert

This Code is written on the basis of some condition, it has lead time of 3 weeks with Very high risk change and and so on,

user8928938913
Tera Expert

@Samartha Shetty  - thank you for the code, it is working wonderfully but there is one slight correction, wondering if you can assist.

 

During testing, I noticed that the newStartDate time is populating in UTC time:

 

gs.addErrorMessage('Planned Start Date Should be after ' + newStartDate + " for Normal Change With "+r);

 

 

Would you know how to get this value to display in local time?

 

Edit - figured it out - for those that come across this, you can get the local display time to show up by adding the getDisplayValue():

gs.addErrorMessage('Planned Start Date Should be after ' + newStartDate.getDisplayValue() + " for Normal Change With "+r);

 

Samartha Shetty
Tera Expert

Hi 

You can use getLocalTime() function with the GlideDateTime

 

ex:

var newStartDate=new GlideDateTime().getLocalTime();

 

I believe this should work.

 

Thanks

Samartha C Shetty

sayali97
Tera Contributor

Hi @Samartha Shetty 

 

Thank you for the solution but when I am testing there is no error message. the time is in UTC only. 

 

 

Samartha Shetty
Tera Expert

Hi @sayali97 

Please check if the code is entering the if statement, If not check if both start and end date is in same tz.

Mary35
Tera Expert

how are you handling the lead time when rejecting a Normal Change record? Are you having it reset or will it hold the lead time for corrections so the user can keep the same implementation date

 

Kimberly8
Tera Explorer

Is there a way to setup a lead time for normal changes for medium and low risk to before a CAB Meeting.  I want to prevent changes from being submitted minutes before CAB.  I want to set 2 business day lead time before our CAB Meetings.  

Version history
Last update:
‎03-03-2020 11:16 AM
Updated by: