How to modify the Original Estimate field with Script Runner?

Hello,

I created a Groovy script to copy the Story Point to Original Estimate.
My script works if the time spent by the user on an issue is not specified. If the time spent is specified, my script can’t change the Original Estimate field.

Here’s my code

String requestJQL = "project = IDMOK AND 'Story Points' is not EMPTY"

ComponentAccessor componentAccessor = new ComponentAccessor()
def user = componentAccessor.getJiraAuthenticationContext().getLoggedInUser();
SearchService searchService  = componentAccessor.getComponentOfType(SearchService.class) 
SearchResults response = searchService.search(user, new DefaultJqlQueryParser().parseQuery(requestJQL), PagerFilter.getUnlimitedFilter() )

CustomFieldManager customFieldMng = componentAccessor.getCustomFieldManager();
def storyPointValue
Long OriginalEstimateValue
MutableIssue mutableIssue
 
response.getIssues().each() {
    mutableIssue = componentAccessor.getIssueManager().getIssueObject(it.getKey())
    storyPointValue = mutableIssue.getCustomFieldValue(customFieldMng.getCustomFieldObject("customfield_10022"))
    
    if (storyPointValue != null) {
        OriginalEstimateValue = 86400 * (Long) storyPointValue //Convert
        mutableIssue.setOriginalEstimate(OriginalEstimateValue)
       
        componentAccessor.getIssueManager().updateIssue(user, mutableIssue, EventDispatchOption.DO_NOT_DISPATCH, false)
    }
}

Here on the left an issues with time spent (logged) field not specified, the script modify the Original Estimate (Estimated).
On the right an issue with time spent (logged) field specified, the script can’t modify the Original (Estimated).

I read this article, but it has not changed anything Time tracking
How to modify the Original Estimate of an issue that has filled the time spent ?

Thanks.

you already logged work. you can’t update the estimate after that. if you hadn’t the code would have worked.

sorry - only one cup of coffee today. That’s just how it works. If you want to update the original estimate after you’ve logged work you have to hit the database. Ultimately time remaining is way more important than the original estimate for tracking anyway.

Just so people can yell at me, I used to update JIRA directly to add a condition to atlassian-jira/WEB-INF/classes/system-issueoperations-plugin.xml so people couldn’t log work unless an estimate was set.

Thanks for your feedback justin_shapiro. If i hadn’t the code it’s work, i can change manually the Original Estimate though i have logged work.

Hello.
You can use the store() method of MutableIssue, this way it will update the Original Estimate even with inserted data

//issueManager.updateIssue(null, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
issue.store();