Setting a due time within a post function

Franzi Joseph July 7, 2021

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
David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 7, 2021

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
}
Franzi Joseph July 7, 2021

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

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 7, 2021

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

Franzi Joseph July 7, 2021

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

Paul A Wright October 21, 2022

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

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.

0 votes
Franzi Joseph July 13, 2021

Hi @David Fischer ,

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

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 13, 2021

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
}
Franzi Joseph July 13, 2021

Hi @David Fischer ,

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

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 14, 2021

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
AUG Leaders

Atlassian Community Events