Add up date/time from 2 custom fields.

Danilo Simic November 25, 2022

Is it possible to add or subtract the date/time from a custom field?

 

What is needed:

When the ticket is moved to a specific status we populate a date/time field (call it field A) using the smart value {{now}}. Later when the ticket moves out of that status, we get the difference between now and when the ticket entered the status, again using smart values.
(The problem is in this part) We need to then add up the difference that we just got to a date/time field (call it field B) which already has a value.

Example:

  1. Field B value is 23.10.2022. 11:00
  2. Ticket moves to the desired status (Field A is filled in with 23.10.2022. 11:00) and stays there for 2 hours
  3. When ticket moves out of the desired status, we now have 2 hours
  4. Add those 2 hours to Field B
  5. Field B value is now 23.10.2022. 13:00

 

Any other suggestions that will solve this problem in a different way are welcome. Using a plugin is not an option.

I was looking into this document but I could not find a solution: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-date-and-time/

Using JSON in the "Edit issue" module in automation rules is also considered.

 

We need all of this to be part of Jira automation since the calculation needs to be done real time for thousands of tickets.

 

Thank you very much for the help.

 

1 answer

1 accepted

1 vote
Answer accepted
Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 25, 2022

Hi @Danilo Simic - I'm a little confused about the scenario since you're using "Field A and Field B" and it doesn't really make sense to me what you're actually trying to track.

A real world example using the actual fields you are trying to track may lead us to a solution that is simpler.

But just to answer your questions, you can find a difference between now() and a date from another field by using the diff command, as described on that page you referenced.

And you can add time to an existing field by using the plus* command. So I think I achieved what you wanted by creating an Edit Issue action for Field B with the following Smart Value:

{{issue.Field B.plusMinutes(issue.Field A.diff(now).minutes)}}

Please let me know if this works!

Danilo Simic November 28, 2022

Hi @Darryl Lee

Sorry about the confusing explanation.

This will solve my problem. I could not find a smart value expression for adding up two date/time fields.

 

To further elaborate. We now have a field called "Expected Restoration Date" which is a date/time field type. Based on ticket priority we calculate the date/time for "Expected Restoration Date" (Example: If priority is Blocker then we add 8 hours to the ticket created date and fill in "Expected Restoration Date").
However this had the problem that the time in "Expected Restoration Date" field was never updated (it does not account for the time while we are waiting for the customer to provide more information).

So we wanted to include that calculation. The idea we came up with is creating a new field for storing the date/time of when the ticket is moved to the status "Waiting for Customer". Then based on that, once we transition the ticket to some other status we see how much time passed while the ticket was in that status and we add that time to "Expected Restoration Date".

 

Sorry for the text wall and for the bad explanation. I hope this clears things a bit.

Thank you very much for the smart value you provided. I think this is exactly what we need.

Darryl Lee
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 28, 2022

Ah, that makes more sense now. Thank you! I'm glad I was able to help!

Suggest an answer

Log in or Sign up to answer