Scriptrunner additional issue actions: set original estimate

Ovidiu Vasilescu August 11, 2016

I am creating a very waterfall-ish workflow. I know what happens at every step of the way and how long (roughly) it's going to take.

I need to create 3 issues at a certain point of the workflow (clone issue and link) and set different (hardcoded) original estimates for each of them. 

What I'm thinking is something along the lines of:

issue.setOriginalEstimate(10d)

issue.OriginalEstimate = 10d

 

I feel this shouldn't be incredibly difficult but for some reason I can't manage it and I can't find any similar topic in the tome of google.

1 answer

1 accepted

2 votes
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 11, 2016

You're close, but there's a couple of things to understand about the estimate field.

First, it's a length of time, and held internally in either seconds or milliseconds (I can never remember which).  So you need to feed it a simple, large number

Second, the 10d thing is done in code for the front end and it's about making a duration pretty for the users.  They can write, and see, 10d for "10 days", but it's all (milli)seconds in the actual code and data.

Last, the java API can be very helpful - bookmark https://docs.atlassian.com/jira/latest/ - it's not what I'd call "good" documentation in that 99.9% of it is not explained in human terms, but it does what javadoc is supposed to - lists the calls and their input/output. 

So, to answer it without you following any links, try:

issue.setEstimate ( 10 * 24 * 60 * 60 )  

That assumes seconds, and a 24 hour working day though, so you might need to tweak it.

Ovidiu Vasilescu August 12, 2016

Thanks for that, it's very useful info.

One thing though, what method do I need to import for this? 

As you can see, I tried importing MutableIssue but it doesn't fix the error.image2016-8-12 12:56:4.png

 

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 12, 2016

Where is this script running?  If it's a post-function, I'm not sure you need import anything.

Ovidiu Vasilescu August 12, 2016

Yep, it's a Script Post-Function / Clones an Issue and Links.

 

The other imports are for a different function, I need to set a custom field as well for the issues that I clone.

Steven F Behnke
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 12, 2016

If you check the documentation you should see your mistake, but I'll help you out here. The built-in IDE-like syntax magic is exactly right, there is NO method of com.atlassian.jira.issue.MutableIssue#setEstimate(int). It does not exist. There IS a method of com.atlassian.jira.issue.MutableIssue#setEstimate(Long).

This is probably due to storage-size; A JAVA Long is 64-bits long whereas a JAVA Int is only 32-bits long – Useful for storing time in milliseconds.

TL;DR Cast your value as a Long, not an Int ( issue.setEstimate(Long 288000) )

Ovidiu Vasilescu August 16, 2016

My willingness to read the documentation is not the issue - it's just that I don't have a technical background so in case it's not written in a somewhat plain fashion, I will not understand it. So don't feel bad for helping me out, it's much appreciated smile

 

I've tried your solution and it's giving me another error. Also I'm assuming it should be " long" , not "Long". I tried both and they're the same error anyway.

image2016-8-16 13:22:50.png

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 16, 2016

The difference between variable types still catches me when I'm scripting.  Although I completely understand why there are types, coming from a school of coding where every operation mattered, you explicitly tell the code to use the most efficient (working with integers is faster than longs, which are faster than doubles, so you always use the smallest that can contain your answer).  As a human, they're all "numbers", we don't think in types of number, so it's not intuitive.

Try coding explicitly, the long way, and shorten it later.  For example, for 10 days:

long my_result = 10 * 24 * 60 * 60 * 1000
issue.setEstimate ( my_result )

Although I suspect you can just do a "cast" too -

issue.setEstimate ( (long) 288000 )

Ovidiu Vasilescu August 16, 2016

Many thanks Nic and Steven for helping me out with this!

Both of the options described by Nic are working. I'll mark this as solved - cheers!


EDIT: Also, just to be clear, there's also no need to import anything. Just the one line is enough: 

 issue.setEstimate ( (long) 288000 )


Suggest an answer

Log in or Sign up to answer