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

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

1 vote
Answer accepted

Hi @Franzi Jos ,

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 :)

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 Jos 

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
Community showcase
Published in Jira

⏰ Day in the life of a Jira Admin!

Hello Community! We thoroughly enjoyed this just-for-fun conversation in the Jira Admin Group about what it's like to be a Jira Admin. For #JiraJuly, our talented designers created these graphics t...

497 views 2 17
Read article

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