Calculate business days between start date and due date, then insert into new issue field
Asked by patricia.ambichler:

Hello all!

I'm struggling with a jira automation on a business board.

The issue fields concerned:

\* Due date

\* Start date (as far as I can see, it was created by a jira admin)

\* Length (I've tried a number and text field)

Goal: when an issue is updated, start and due dates are both not empty, then calculate the business days between them and insert them into the new field "Length". Format of output is irrelevant (eg 5, 5.0, 5 days) - everything goes.

Smart value I have tried:

{{issue.duedate.diff(issue.startdate).businessDays}}

Also with issue field IDs and calculation {{#=}} \& {{/}}


Answers:
author: Trudy Claspill
body: Hello [@patricia.ambichler](/t5/user/viewprofilepage/user-id/5536756)

Welcome to the Atlassian community.

Whenever asking for help with an Automation rule, it will help us help you if you provide screen images showing the complete rule and the details of each step.

In the case where the rule is not doing what you expect it will also help us if you provide all the details from the rule Audit Log for a time when the rule executed, and if you tell us what you expected the specific result to be and what the actual result was.

Lastly, when using smart values the field names you use in them are case sensitive and space sensitive. If "Due date" and "Start date" are the field names you see in the screen, then try using

{{issue.Due date.diff(issue.Start date).businessDays}}

comments: author: patricia.ambichler
body: Hello [@Trudy Claspill](/t5/user/viewprofilepage/user-id/3569011) , thank you so much!

I've tried various versions of the smart value, including "Due date" and the IDs.

I don't know how much the audit log will help, as it says "success" but the issue field Length never changes.


author: patricia.ambichler
body: Does it matter, what type of field Length is?


author: Trudy Claspill
body: Text or number should be fine for the Length field.

A debugging technique that is available to you is to use the Log action to print into the rule Audit Log the values of the smart values you are trying to use. That will help you determine if the right information is being obtained from the issue.

![Screenshot 2024-07-04 at 11.52.38?PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/333644i15F2FDB3F6B085ED/image-size/large?v=v2&px=999 "Screenshot 2024-07-04 at 11.52.38?PM.png")

If you can do that and run the rule again, and provide the requested screen images, and an image of the issue against which the rule ran showing the Due date and Start date fields, we will be better able to help you diagnose the problem.


author: patricia.ambichler
body: That's a helpful tip, thanks! \& the result is very interesting.

![TestTicket.png](https://community.atlassian.com/t5/image/serverpage/image-id/333646iD234D87B7BB9DA52/image-size/large?v=v2&px=999 "TestTicket.png")![TestResult.png](https://community.atlassian.com/t5/image/serverpage/image-id/333647iD5E42A5637D529E2/image-size/large?v=v2&px=999 "TestResult.png")![TestRule.png](https://community.atlassian.com/t5/image/serverpage/image-id/333648i668808AE7388DD74/image-size/large?v=v2&px=999 "TestRule.png")


author: Trudy Claspill
body: But what do you get when you add the Log actions to your own rule?


author: patricia.ambichler
body: The "right" answer, just with a negative - (still with a manual trigger)

![Screenshot 2024-07-05 091701.png](https://community.atlassian.com/t5/image/serverpage/image-id/333654i37D0182DB586478C/image-size/large?v=v2&px=999 "Screenshot 2024-07-05 091701.png")


author: Trudy Claspill
body: It would be helpful if you put those Log actions into your actual rule and execute the action that triggers your rule to run. Then show us **both**your complete automation rule and the output in the Audit Log from the rule execution.

If you aren't getting the expected result in your actual rule, we need to see that information to debug the reason.


author: patricia.ambichler
body: To achieve no (-) in the Length field, I swapped the start and due dates in the smart value

The log, completed rule,and ticket below. It's interesting because the log now shows (-) but the ticket field is correct. Not sure what exactly is happening with the result, but happy with it.

Thank you so much for your help [@Trudy Claspill](/t5/user/viewprofilepage/user-id/3569011) !

![Screenshot 2024-07-08 083622.png](https://community.atlassian.com/t5/image/serverpage/image-id/333905iE5A2AB20026206CD/image-size/large?v=v2&px=999 "Screenshot 2024-07-08 083622.png")![Screenshot 2024-07-08 083649.png](https://community.atlassian.com/t5/image/serverpage/image-id/333904iA25E8D31552908D7/image-size/large?v=v2&px=999 "Screenshot 2024-07-08 083649.png")![Screenshot 2024-07-08 083711.png](https://community.atlassian.com/t5/image/serverpage/image-id/333903iBC4B352A2E63C750/image-size/large?v=v2&px=999 "Screenshot 2024-07-08 083711.png")


author: Trudy Claspill
body: You can use the **abs** function to have the final result be a positive number regardless of how you arrange the date fields in the statement. There an example of that in the documentation about the date difference function.

<https://support.atlassian.com/cloud-automation/docs/jira-smart-values-date-and-time/#Date-difference--->

If my answer thread has helped you solve your requirement please consider clicking on the Accept Answer button to mark your post as Solved.


Tags: cloud

jira-cloud