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

I'm not quite sure what the blank error message was, unless the blank error was the one that normally says "Invalid update" (which shows up whenever you use "current.setAbortAction(true)".



Based on your other reply saying you figured it out, we'll just table this.



Glad you got it working!


So, I have De-activated the first rule I set up and created it again and it works fine. Both had been copied and pasted but ill compare side by side and see if I can spot the problem. if I find anything ill post in this thread for future reference. Thanks for your help. Most appreciated.


Wow! It's always nice when something like that happens to fix the issue. Let me know if you can figure out what happened, sounds like a very interesting case study.


Will do. Knowing me its something really obvious I have overlooked. When I


find it ill let you know.



On 23 October 2014 14:59, Garrett Griffin-Morales <