- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2014 04:52 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2014 09:29 AM
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));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2014 09:29 AM
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));
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2014 01:06 AM
Thanks Garrett,
That's worked a treat.
Most appreciated.
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2014 01:16 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2014 03:09 AM
Garrett,
7*8*60*60 should not be 7*24*60*60 ?
Cheers
Maros