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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,461,953
Community Members
 
Community Events
176
Community Groups

Setting a due time within a post function

Hello all,

I would like to set an automated due date/time within a post function of an issue. I already managed to set the "due date" custom field with the postfunction "Set field value of related issues (JMWE app)" where I said for example new Date() + 14 to set a due date 14 days after issue creation. But I could not manage to set the "due date/time" custom field to a due time of for example 2 hours after creation. How would this look like?

Thanks in advance,

BR
Franzi

2 answers

1 accepted

2 votes
Answer accepted

Hi @Franzi Joseph ,

it's basically the same thing, except that to add hours you should use:

use (groovy.time.TimeCategory) {
  return new Date() + 2.hours
}

I am not that deep into that script. Can I copy and past it like that or do I have to exchange this (groovy.time.TimeCategory) with something? Could you write it down so that i can just copy/paste it? :D

It can be used as is (assuming you want "2 hours from now" as the value)

Hi David, thanks so much, that worked perfectly :)

This is exactly what I was looking for, thank you @David Fischer _Appfire_ 

I wanted to change this to a year, so took a punt and changed 2.hours to 1.year and it worked a treat.

Thank you for sharing.

Hi @David Fischer _Appfire_ ,

I have one additional question. Do you also have an idea how to exclude weekends here, so for example if I say

use (groovy.time.TimeCategory) {
return new Date() + 2.days
}

how can I make sure that Saturday and Sunday will not count here?


BR
Franzi

Hi @Franzi Joseph 

it's a little ugly, but you can do:

use (groovy.time.TimeCategory) {
def d = new Date() + 2.days
if (d.day == 6)
d = d + 1.days
if (d.day == 0)
d = d + 1.days
return d
}

Hi @David Fischer _Appfire_ ,

I tried with setting due date five days from today and normally it should give me the 21st then but it still gives me the 19th, which means it is counting the weekends. So looks like it doesn't work.

BR
Franzi

Right, it only works for adding 2 days, as in your example.

Try this instead:

def d = new Date()
for(i=0; i < 5; i++){
d = d + 1
if (d.day == 6)
d = d + 1
if (d.day == 0)
d = d + 1
}
return d

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events