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

Calculated number fields - Calculate WORKDAYS

Christian Vorraber May 20, 2014

Dear all,

I'm currently trying to implement a custom field whose content should be calculated according to some other fields in the issue.

One part of the formula is to calculate the amount of workdays between two dates.

I already managed to calculate the days in between two dates but I only want to get the real workdays - so that Saturdays and Sundays are not included.

Would be great if you can help me with that.

Currently the calculation for days in between two days looks like this:

((new Date()).getTime())-(issue.get("customfield_10440").getTime())

Thanks for your help!

Kind regards,

Markus

5 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Christian Vorraber May 28, 2014

Finally I found the issue. The return value wasn't casted right - it seems that JIRA gets problems especially when creating the issue.

Thanks for your help.

Carla Dumale November 6, 2018

Hello, may I ask how did you managed to count workdays of the specific issue excluding the holidays and weekends? Thank you!

Like Matthew_Schulz likes this
0 votes
Christian Vorraber May 22, 2014

I investigated the code today but I didn't manage to fix it.

So I created a new script field and only added "return 10;" - that's it.

Suprisingly this also didn't work and JIRA still says: Error creating issue: Error occurred while creating issue. This could be due to a plugin being incompatible with this version of JIRA. For more details please consult the logs, and see:http://confluence.atlassian.com/x/3McB.

So it has nothing to do with wrong coding - do you have ideas what else it could be?

I use Script Runner 2.1.16

0 votes
Christian Vorraber May 21, 2014

I need to check - unfortunately I don't have direct access to the server and would need to ask IT for log files.

How could i try out if this is the root cause. How can I include a condition, so that code is only executed once the issue is created? (or only on update)

Kind regards,

Markus

0 votes
Christian Vorraber May 21, 2014

Thanks for your answer Andreas!

I managed to implement a similar function than supposed in the link. It works fine on existing issues but when I want to create new ones it says: Error creating issue: Error occurred while creating issue. This could be due to a plugin being incompatible with this version of JIRA. For more details please consult the logs, and see: http://confluence.atlassian.com/x/3McB .

Do i need to consider sth. else? E.g. that the script is only executed on a specific event? Could it be that it can't get the values of the fields since the issue isn't already present?

Kind regards,

Markus

Andreas Ebert
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.
May 21, 2014

For more details please consult the logs

Well, was does the logs say? But I also think that is has to do with not-yet-created data for new issues.

0 votes
Andreas Ebert
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.
May 20, 2014

That is not a trivial task. If you want to do it correctly, you should also exclude holidays from the "amount of workdays". And which holidays apply depends on your country and maybe even your state or region.

I would probably loop through all days from issue.get("customfield_10440") to new Date(), and check for each date if it is a workday or not, and add +1 if it is a workday. Something like this stackoverflow answer.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events