Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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 Community Leader Jan 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

Huge help :) Thank you, Payne!

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 Community Leader Feb 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

Thank you @Payne ! Really appreciate it.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

3,888 views 11 5
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you