We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

VaranAwesomenow
Mega Sage

fix script to do lead time calculation, This can be used in a script include and called via client script by passing right variable values.

This script compares date diff between planned start date, current date using a schedule of your choice.

 

var sLog = '';

var isValid = false;

var plannedStartDate = new GlideDateTime();

plannedStartDate = getStartDate();

var dc = new DurationCalculator();

dc.setSchedule('7808de182f91e850f101ad2ef699b659' ); // schedule of CAB

var gdt = new GlideDateTime();

if(dc.calcScheduleDuration(gdt,plannedStartDate) >0) {

                isValid = true;

}

sLog = "start Date =" + plannedStartDate;

sLog+= " Current Date= " + gdt;

sLog += " Is Date Valid =" + isValid;

gs.print(sLog);

 

function getStartDate() {

                var grChg = new GlideRecord('change_request');

                grChg.get('7557790f378c1300023d57d543990ed5');

                return grChg.start_date;

}

Youtube link with explanation of script

ServiceNow change management - CalculateChangeLeadTime - YouTube

Updateset is available here https://developer.servicenow.com/connect.do#!/share/contents/3287388_fix_script_to_calculate_difference_between_planned_start_date_and_current_date_of_a_change_request?t=PRODUCT_DETAILS

Comments
tiagomacul
Giga Sage

Hi Anil,

 

 I linked your article here "Scripts:: compareDates();"

 

Regards

VaranAwesomenow
Mega Sage

Ty Tiago 🙂

Version history
Last update:
‎12-21-2020 05:01 AM
Updated by: