- 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-23-2014 06:57 AM
Not in this case. The schedule the code is comparing against is an 8 hour per day schedule. Since I'm using the schedule to calculate how many valid working seconds have passed, I need to compare against business time and not calendar time.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2014 07:00 AM
makes sense !

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2014 09:35 AM
Hello Steve,
You could check for the date difference on the server side as Garrett Griffin-Morales has suggested above. However, if you want the check to be on client side itself, you could do so using Ajax call.
Here are some useful functions for the same.
Client Script Date/Time Functions
Hope that helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2014 01:58 PM
Hey Steve, sorry for the delayed reply.
I just spent 10 minutes testing both versions in my instance, and they're working as I would expect.
Which method are you using? I suspect you're using the second method, that goes along with a schedule?
If that's the case, do me a favor and try using this verbatim in your script section:
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 business days in the future.");
}
function calcLeadTime(start,begin){
var dc = new DurationCalculator();
dc.setSchedule('090eecae0a0a0b260077e1dfa71da828',"");
return(dc.calcScheduleDuration(begin,start,true));
}
-------
If that doesn't work, double check that the sys_id on the third to last line (090eecae0a0a0b260077e1dfa71da828) matches that of the schedule you're wanting it to run against:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2014 12:49 AM
Hi Garrett.
It was the first one I have been trying however I have tried the second following the above and its throwing up 2 error messages. One is because the change is not 7 days ahead and one is blank. When I amend the dates I no longer get the "must be 7 days ahead" warning but I still get the blank error. This only happens if the change is high. Is there something wrong with my condition as I cant find anything else that only relates to high. My current condition is,
(current.start_date.changes() || current.impact.changes()) && current.impact == 1
Any thoughts?