Jira Date diff automation
Asked by Sunny Kanojia:

Hi Team,

I used date diff query to automate RCA being recorded and it is giving a success response but the custom field that must be edited is not getting edited.

![Screenshot 2024-06-18 at 2.43.07?PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/330327iB202C47C51136777/image-size/large?v=v2&px=999 "Screenshot 2024-06-18 at 2.43.07?PM.png")![Screenshot 2024-06-18 at 2.43.14?PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/330326i129DA21A62AC55EF/image-size/large?v=v2&px=999 "Screenshot 2024-06-18 at 2.43.14?PM.png")![Screenshot 2024-06-18 at 2.43.25?PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/330328iB0B7C029E25C5BA1/image-size/large?v=v2&px=999 "Screenshot 2024-06-18 at 2.43.25?PM.png")


Answers:
author: Tansu Akdeniz
body: Hi [@Sunny Kanojia](/t5/user/viewprofilepage/user-id/5523156)

Welcome to the community.

Please first check how diff function is used from here: <https://support.atlassian.com/cloud-automation/docs/jira-smart-values-date-and-time/>

It seems there is something wrong in your usage.

Also, take a look at this existing thread: <https://community.atlassian.com/t5/Jira-questions/automation-for-date-difference/qaq-p/2343981>

Don't forget to check Audit Logs.

If problem persists, share your formula here in text.

comments: author: Bill Sheboy
body: Hi [@Sunny Kanojia](/t5/user/viewprofilepage/user-id/5523156) -- Welcome to the Atlassian Community!

Adding to Tansu's answer:

There is definitely an error in what you show for using the diff() function to set the "RCA TAT" field.

Please post the smart value expression you have in that field so the community can offer suggestions. Thanks!

Kind regards,  
Bill


author: Sunny Kanojia
body: Hi Tansu and Bill,

Thanks for your response. In the RCA TAT, which is a number field, I am trying to capture the difference in hours between two dates, both the events having date and time information. I am getting a success response of the query but the 'RCA TAT' field is still empty.

The query I am using is :

{{(issue.customfield_10149)diff(issue.customfield_101649.hours}}


author: Bill Sheboy
body: Please try this update as you had some misplaced parentheses:

```
{{issue.customfield_10149.diff(issue.customfield_101649).hours}}
```


author: Sunny Kanojia
body: ![Screenshot 2024-06-20 at 9.10.41?AM.png](https://community.atlassian.com/t5/image/serverpage/image-id/330726i4D317E7B44D75B61/image-size/large?v=v2&px=999 "Screenshot 2024-06-20 at 9.10.41?AM.png")![Screenshot 2024-06-20 at 9.11.04?AM.png](https://community.atlassian.com/t5/image/serverpage/image-id/330727i435E3EBE883A9EAD/image-size/large?v=v2&px=999 "Screenshot 2024-06-20 at 9.11.04?AM.png")![Screenshot 2024-06-20 at 9.12.11?AM.png](https://community.atlassian.com/t5/image/serverpage/image-id/330728i5FA9FBE7DA55671B/image-size/large?v=v2&px=999 "Screenshot 2024-06-20 at 9.12.11?AM.png")Hi Bill, with the updated query, it is giving the success but automation is making the RCA TAT recorded to none, as before. Please advise.


author: Bill Sheboy
body: Here are some follow-up questions to try to diagnose this symptom:

1. What type of project is this: company-managed or team-managed? You may find that at the bottom-left of the screen expanding area.
2. Are those custom fields configured in Jira or from a marketplace addon / app?
3. Have you confirmed with admin functions both of those fields are date / time field types?
4. Have you confirmed those are the correct custom field id values for the fields?
5. Have you confirmed both fields have date / time values when the rule runs? You may confirm that by writing both values to the audit log before the field is edited in the rule.
6. Have you tried writing the diff() expression to the audit log to check if the expression is correct, but the problem is storing the result: {{issue.customfield_10149.diff(issue.customfield_101649).hours}}


author: Harsh
body: Hi [@Sunny Kanojia](/t5/user/viewprofilepage/user-id/5523156)   

Can you tell what field type is RCA TAT and what exactly you want. The automation is bit confusing.  

Thanks!

comments: author: Sunny Kanojia
body: Hi Harsh,

Thanks for your response. In the RCA TAT, which is a number field, I am trying to capture the difference in hours between two dates, both the events having date and time information. I am getting a success response of the query but the 'RCA TAT' field is still empty.

The query I am using is :

{{(issue.customfield_10149)diff(issue.customfield_101649.hours}}


author: Harsh
body: Hi [@Sunny Kanojia](/t5/user/viewprofilepage/user-id/5523156)   

Instead of directly copying value, you can create a variable first with the smart value to calculate the difference.

And then add that created variable as a smart value {{variablename}} to RSA TAT field.

You can also log action to debug if the smart value mentioned above is actually giving the difference.

Thanks!


author: Sunny Kanojia
body: Hi Harsh,

Please can you elaborate how can i do this.


author: Harsh
body: Sure,  

Trigger: When issue transitioned

Condition: Issue type equals

Action: Create Variable. Lets call it as: datedifference, in smart value put the following: {{#=}} {{issue.date1.diff(issue.date2).days}}{{/}}

**{{#=}} implies math formula just for context**

Edit Action: Create a log action and put {{datedifference}} to debug if it calculating or not.

Edit Action: Edit Issue: Choose the RSA TAT field, and put the {{datedifference}}.  

This should work because I have used the same mechanism several time.

In any case let me know if it works or not.


Tags: cloud

jira-cloud