automation for jira using smart value: plusDays using diff doesn't work
Asked by Eric Brandenburg:

Context, on a ticket, i have :

* an issue date field
* a date automatically set when I transit a ticket into the blocked externally column

What I want to do : calculate the new issue date when the ticket comes back to the "in progress" column

For example :

* issue date = 15/08/2024
* start of externally blocked = 09/08/2024 ("issue.customfield_10246")

On the 18/08/2024 I move back the ticket into the "In progress" column, the new issue date should then be 25/08/2024 (Now + (15/08 - 09/08) = 25/08)  
You follow me ?   

I'm new to smart value and SQL function so I tried something exotic but it doesn't work :

{{now.plusDays(duedate.diff(issue.customfield_10246.toDate).businessDays}}

<br />

Anyone figuring this out here ?   

Thanks you so much in advance


Answers:
author: Marc - Devoteam
body: Hi [@Eric Brandenburg](/t5/user/viewprofilepage/user-id/5086061)

Welcome to the community.

The diff smart value option is for calculation between date, the output will be a number no a date, as its a calculation.

toDate smart value option is only able to convert text information to a date, and that text needs to be in the correct format

So what could be done is that you:

1. calculate the number of difference, store this in a field in Jira
2. re-fetch the issue data
3. then edit the issue date now plus the number of days in difference, it might be that you need to store the value form the number field in a variable before you can use it in the calculation

comments: author: Eric Brandenburg
body: Thanks to both of you, I got a "success" on that automation but the result is not the one expected.

My custom field is already a date fiel so it works fine as it is without the "toDate".  

```
{{now.plusDays(issue.duedate.diff(issue.customfield_10246).businessDays)}}

which in calculation should look like that : 

{{14/08.plusDays(issue.15/08.diff(issue.12/08).businessDays)}}
```

<br />

But the calculation went wrong :   
I had :   
due date = 15/08  
start of blocked ticket = 12/08 (my customfield_10246)  
So the result expected when putting the ticket back in the "in progress" column was due date = 17/08 but I got due date = 11/08 instead

<br />

![Screenshot 2024-08-14 at 11.27.23.png](https://community.atlassian.com/t5/image/serverpage/image-id/341687i8B24226352448B82/image-size/large?v=v2&px=999 "Screenshot 2024-08-14 at 11.27.23.png")  


author: Marc - Devoteam
body: Hi [@Eric Brandenburg](/t5/user/viewprofilepage/user-id/5086061)

First try

```
{{issue.duedate.diff(issue.customfield_10246).businessDays}}
```

What is the outcome?


author: Eric Brandenburg
body: Ok, I wanted to do it all in one formula but let's go step by step as you suggest, maybe easier.  
So I created this automation rule :

{{issue.customfield_10246.diff(now).businessDays}}

--\> that works, success, and gives me the number of BusinessDays the ticket spent in the externally blocked column (customfield_10246)

![Screenshot 2024-08-14 at 14.47.57.png](https://community.atlassian.com/t5/image/serverpage/image-id/341729iE3519C4FBA42DFBD/image-size/large?v=v2&px=999 "Screenshot 2024-08-14 at 14.47.57.png")

I then added a second rule (screenshot below) to add that number to the due date, it says success but I lost the value in the duedate field, it's now blank so it didn't work :

{{duedate.plusBusinessDays(issue.customfield_10329)}}

![Screenshot 2024-08-14 at 14.48.33.png](https://community.atlassian.com/t5/image/serverpage/image-id/341730i995992E12E1D2844/image-size/large?v=v2&px=999 "Screenshot 2024-08-14 at 14.48.33.png")

result on the ticket :

![Screenshot 2024-08-14 at 14.51.45.png](https://community.atlassian.com/t5/image/serverpage/image-id/341733i8B9F62739D296644/image-size/large?v=v2&px=999 "Screenshot 2024-08-14 at 14.51.45.png")

Any idea on this one ? This one should have been easy, no ?


author: Marc - Devoteam
body: Hi [@Eric Brandenburg](/t5/user/viewprofilepage/user-id/5086061)

Try, {{issue.duedate.plusBusinessDays(issue.customfield_10329)}}

Otherwise to create a variable that stores the number from the field "Nb de jours...."

lets call the variable {{days}}

{{issue.duedate.plusBusinessDays({{days}})}}


author: Eric Brandenburg
body: I didn't quite get the variable days thing but no need, adding "issue" works like a charm. Thanks a lot for your precious help on this one, really appreciate it !


author: Bill Sheboy
body: Hi [@Eric Brandenburg](/t5/user/viewprofilepage/user-id/5086061) -- Welcome to the Atlassian Community!

For a question like this, please post an image of your complete automation rule, images of any relevant actions / conditions / branches, an image of the audit log details showing the rule execution, and explain what is not working as expected. Those will provide context for the community to offer ideas. Thanks!

Until we see those...

Assuming your customfield_10246 is text, the expression you show is missing a closing parenthesis at the end:

```
{{now.plusDays(issue.duedate.diff(issue.customfield_10246.toDate).businessDays)}}
```

If instead your customfield_10246 is a date or date / time field, the toDate conversion may be removed:

```
{{now.plusDays(issue.duedate.diff(issue.customfield_10246).businessDays)}}
```

Kind regards,  
Bill

comments: author: Eric Brandenburg
body: Thanks [@Bill Sheboy](/t5/user/viewprofilepage/user-id/1685313) and sorry for the missing screenshot. See my answer to marc below if you can help  
Thanks again


Tags: automation

cloud

dates

diff

jira-cloud

smart-value