Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Normal Change lead time

siva44
Tera Contributor

Hello to everyone,

I have write the on change client  script for normal change planned start date lead time 24 hours but it takes the 30 hours time The script follws below:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
   
    var startDate = g_form.getValue("start_date");
    var endDate = g_form.getValue("end_date");
    var date_in_5 = new Date();
    date_in_5.setDate(date_in_5.getDate()+1);
    var format = g_user_date_time_format;
   
    // get date strings into a number of milliseconds since 1970-01-01
    var startDateMs = getDateFromFormat(startDate, format);
    var endDateMs = getDateFromFormat(endDate, format);
   
    var dd = date_in_5.getDate();
    var mm = date_in_5.getMonth()+1; //January is 0!
    var hh = date_in_5.getHours();
    var min = date_in_5.getMinutes();
    var ss = date_in_5.getSeconds();
   
    if(dd<10) {
        dd='0'+dd;
    }
   
    if(mm<10) {
        mm='0'+mm;
    }
    if(hh<10) {
        hh='0'+hh;
    }
    if(min<10) {
        min='0'+min;
    }
    if(ss<10) {
        ss='0'+ss;
    }
   
    date_in_5 = dd + "/" + mm  + "/" + date_in_5.getFullYear() + " " + hh + ":" + min + ":" + ss;
    var date_in_5MS = getDateFromFormat(date_in_5, format);
   
   
   
    if (startDateMs > endDateMs && endDate != ''){
        g_form.setValue('start_date', '');
        g_form.showErrorBox('start_date','Start date has to be before end date');
    }
   
    if(g_form.getValue('type') == 'normal'){
        if(startDateMs < date_in_5MS){
            g_form.setValue('start_date', '');
            g_form.showErrorBox('start_date','Normal change lead time is 24 Hours');
        }
    }
   
}

 

2 REPLIES 2

Anurag Tripathi
Mega Patron
Mega Patron

Hi,

Why not use No Code ui policy conditions like this and have a much simpler implementation. In the script part you can throw the error.

AnuragTripathi_0-1700144924171.png

 

-Anurag

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @siva44 

 

@Anurag Tripathi  suggested correctly. Use UI policy and no need to build code or use can create property and use that property to validate. 

 

https://www.servicenow.com/community/developer-forum/is-there-an-oob-how-to-modify-lead-time-for-cha...

 

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************