start date must be 7 days ahead

scottjus82
Kilo Guru

Hey all,

 

How would I script a prompt that stops a change with an impact of high being logged less then 7 days ahead of the date the change is being raised. I have tried amending the script that stops changes having an end date before planned date but have not got it right.

 

Any hep would be appreciated.

 

Regards

1 ACCEPTED SOLUTION

GRGisMe
Mega Expert

Something like this should give you a good jumpstart:



When:Before Update



Condition: (current.start_date.changes() || current.impact.changes()) && current.impact == 1



Script:



if(current.start_date <= gs.daysAgo(-7)) {


    current.setAbortAction(true);


    gs.addInfoMessage("The planned start date must be more than 7 calendar days in the future.");


}




If you're wanting it to be 7 business days, it'll be more complicated, with the Script being more like:




if(calcLeadTime(current.start_date, gs.now()) < 7*8*60*60) {


    current.setAbortAction(true);


    gs.addInfoMessage("The planned start date must be more than 7 calendar days in the future.");


}


function calcLeadTime(start,begin){


              var dc = new DurationCalculator();


              dc.setSchedule('SYS_ID_OF_8_TO_5_BUSINESS_DAYS_SCHEDULE',"");


            return(dc.calcScheduleDuration(begin,start,true));


}


View solution in original post

13 REPLIES 13

GRGisMe
Mega Expert

Something like this should give you a good jumpstart:



When:Before Update



Condition: (current.start_date.changes() || current.impact.changes()) && current.impact == 1



Script:



if(current.start_date <= gs.daysAgo(-7)) {


    current.setAbortAction(true);


    gs.addInfoMessage("The planned start date must be more than 7 calendar days in the future.");


}




If you're wanting it to be 7 business days, it'll be more complicated, with the Script being more like:




if(calcLeadTime(current.start_date, gs.now()) < 7*8*60*60) {


    current.setAbortAction(true);


    gs.addInfoMessage("The planned start date must be more than 7 calendar days in the future.");


}


function calcLeadTime(start,begin){


              var dc = new DurationCalculator();


              dc.setSchedule('SYS_ID_OF_8_TO_5_BUSINESS_DAYS_SCHEDULE',"");


            return(dc.calcScheduleDuration(begin,start,true));


}


Thanks Garrett,



That's worked a treat.



Most appreciated.



Regards


I spoke a bit too soon, I have logged a change 1 month in advance that is high and it is still giving me the prompt saying it must be over seven days. What do I need to amend on the script?



Regards


Garrett,



7*8*60*60 should not be 7*24*60*60 ?




Cheers


Maros