Auto populate Original Estimate
Asked by sai chinamuthevi:

Hello Guys,  

we have two fields with name Start date(ID:10038) and end date(ID:10039). Both are date pickers

now my requirement is we want to auto populate value of original estimate based on difference between these two dates.

For example : issue created on september 2nd 2024, and end date mentioned as september 4,2024. i want to auto populate originall estimate as 2d


Answers:
author: Trudy Claspill
body: Hello [@sai chinamuthevi](/t5/user/viewprofilepage/user-id/3803027)

Have you tried to create this rule? Please show us what you have so far.

What event do you want to trigger the setting of the Original Estimate field? Will that be when the issue is created?

What if Start date or end date is changed? Do you want the Original Estimate changed?

What if Start date or end date is cleared; how should that affect the Original estimate?

Should the calculation consider only Business days or all calendar days?

comments: author: sai chinamuthevi
body: Hi Trudy,  

Yes i have created automation rule. But its showing success but Original Estimate is not updating. Please find my Rule screenshot for reference.  
Yes when ever Target start and end date gets changes i want Original Estimate to be changed automatically too and it should consider business days only like 5days a week.  

<br />

![Screenshot 2024-09-17 114240.png](https://community.atlassian.com/t5/image/serverpage/image-id/347650iBFAF39B208BD072C/image-size/large?v=v2&px=999 "Screenshot 2024-09-17 114240.png")


author: Trudy Claspill
body: Hello [@sai chinamuthevi](/t5/user/viewprofilepage/user-id/3803027)

The original estimate is not updating because your syntax is wrong.

It appears that you are first trying to verify that both fields actually contain values. You can do that by adding Conditions to the rule rather than over-complicating the JSON code.

(I used **Start date** and **End Date** in my example. Replace those with the date fields you are using.)

![Screenshot 2024-09-17 at 12.35.40?PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/347833iA1A9713AF0A0C22F/image-size/large?v=v2&px=999 "Screenshot 2024-09-17 at 12.35.40?PM.png")

Next, you don't need to use JSON at all. You can select the Original Estimate field and then set the value using a smart value.

![Screenshot 2024-09-17 at 12.37.14?PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/347834i63F259F8412742C5/image-size/large?v=v2&px=999 "Screenshot 2024-09-17 at 12.37.14?PM.png")

The smart value you would use is:

{{issue.Start date.diff(issue.End Date).days.abs}}d

Again, substitute in the names (or customfield_##### designations) for the fields you actually use.

The **.days.abs** functions indicate you want the difference in days (vs. hours or any other time period) and you want the absolute value (not a negative value).

The **d** at the end is so that the number calculated will be submitted into the Original Estimate field as a value of days, just as if you manually entered **3d**


author: sai chinamuthevi
body: Hi Trudy,  
Its not working as expected. I'm getting below error  

TP-35 (Specify a valid value for Original estimate (timetracking_originalestimate), Specify a valid value for Original estimate (timetracking))


author: Trudy Claspill
body: Hello [@sai chinamuthevi](/t5/user/viewprofilepage/user-id/3803027)

Please provide new screen images of your updated rule and the details of the Edit Issue step.


author: sai chinamuthevi
body: Hi   
Please find rule and Fields attached.  

![Fields.png](https://community.atlassian.com/t5/image/serverpage/image-id/348084iCC7D0A4879920AF7/image-size/large?v=v2&px=999 "Fields.png")![Rule.png](https://community.atlassian.com/t5/image/serverpage/image-id/348085i040D94A3FA29B964/image-size/large?v=v2&px=999 "Rule.png")


author: Trudy Claspill
body: I have two suggestions:

1. Add a **Log** action to print out the value of the smart value you are trying to use.

![Screenshot 2024-09-19 at 9.28.01?AM.png](https://community.atlassian.com/t5/image/serverpage/image-id/348215iE5D9586987FCEF11/image-size/large?v=v2&px=999 "Screenshot 2024-09-19 at 9.28.01?AM.png")

That will add a message to the rule execution log showing the actual value the rule is trying to insert into the Original Estimate field.

2. Add the Conditions I previously recommended to ensure that the date fields actually contain values before you try to use them in a calculation.

![Screenshot 2024-09-19 at 9.25.21?AM.png](https://community.atlassian.com/t5/image/serverpage/image-id/348216iB8DD36ECBB81C3B1/image-size/large?v=v2&px=999 "Screenshot 2024-09-19 at 9.25.21?AM.png")


author: sai chinamuthevi
body: Thanks alot for your response.  
Please find the updated rule and log for your reference :   
Fields i used :   

Start Date  
End date  

Looks like some Minor changes need to be done for rule.![Log.png](https://community.atlassian.com/t5/image/serverpage/image-id/348379i86B7061E73D934CF/image-size/large?v=v2&px=999 "Log.png")![Rule.png](https://community.atlassian.com/t5/image/serverpage/image-id/348380iD5EFD0792B980ECA/image-size/large?v=v2&px=999 "Rule.png")


author: Trudy Claspill
body: There are a few things that may be impacting the outcome of the rule.

1. Sometimes rules that use the Issue Created trigger are triggered before all the data is actually stored. Add a [Re-fetch Issue Data](https://support.atlassian.com/cloud-automation/docs/jira-automation-actions/#Re-fetch-issue-data) action after the trigger to ensure you are getting the full data for the issue.

2.Smart value field names are space and case sensitive. Make sure that the Field Names you use in the smart values match the actual field names in your issue.

3. Jira does not require unique field names. It is possible that there is more than one custom field named "Start Date" or "End date". You may need to use the unique Custom Field ID (i.e. customfield_12345) rather than the field name to ensure you are getting the correct data. For information about finding the custom field ID that matches the field you are using refer to: [Find the Smart Value for a Field](https://support.atlassian.com/cloud-automation/docs/find-the-smart-value-for-a-field/)


author: sai chinamuthevi
body: Hi,  

I used Id's instead of names and yes its working now. i have added refetch issue data too. Thanks alot for the support. :)

Regards.


author: Trudy Claspill
body: I'm glad I was able to help you.

If my responses helped you solve your problem, please consider clicking on the Accept Answer button to mark your post as Solved.


author: sai chinamuthevi
body: Sorry for late reply. But accepted your answer


Tags: cloud

jira-cloud