Automatically set Expected Due Date to 3 business days from Created Date, exclude weekends

Lauren Robinette January 24, 2019

Hi There! I'm trying to update my Expected Due Date field to be 3 business days from the Created Date. This is just a date field (not date/time). I want to exclude weekends (Saturday and Sunday) when calculating the Expected Due Date.

I do have access to ScriptRunner and JMWE to set up this post-function; I'm just unfamiliar with Groovy expressions. I'm using Jira Server v7.10.1.

Any advice would be greatly appreciated!

1 answer

1 accepted

0 votes
Answer accepted
Payne
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 24, 2019

Hi Lauren,

Have a look at https://innovalog.atlassian.net/wiki/spaces/JMWE/pages/156073991/Add+a+certain+number+of+days+to+a+date+excluding+the+weekends

Create a JMWE Scripted Operation post function on your Create transition. Field will be Due Date, Value Type will be Groovy Expression, and Value will be that script, with the final line being date(new Date(),3)

Hope this helps,

Payne

Lauren Robinette January 31, 2019

Huge help :) Thank you, Payne!

Lauren Robinette February 20, 2019

Hi @Payne ! I'm now trying to customize this a bit further. If a user inputs the ticket after 4:00 PM EST, I want to add an additional business day to the due date. I'm currently using the code provided in the link you sent over. Do you have any advice on how to customize?

Thanks, Lauren

Payne
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 20, 2019

Hi Lauren,

So, what you want to do is send an argument of 4 days rather than 3 days if the current hour is 4pm or greater (16 on a 24-hour clock). So, here's one approach; change your final line where you call date(from,nod) to:

Calendar cal=Calendar.getInstance();
def hour = cal.get(Calendar.HOUR_OF_DAY)
def numDaysToAdd = 3 + (hour >= 16 ? 1 : 0)
date(new Date(),numDaysToAdd)

You may not recognize (hour >= 16 ? 1 : 0) ; that's using the ternary operator, which is a way to shortcut an if-then-else construct.

condition ? value if true : value if false

Hope this helps,

Payne

Like David Denney likes this
Lauren Robinette February 21, 2019

Thank you @Payne ! Really appreciate it.

Suggest an answer

Log in or Sign up to answer