Script Runner: groovy postfunction

Hi all,

I'm trying to write a simple script to update original estimate / remaining time on an issue based on a custom field value (nothing too fancy):

import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue;

def myFieldId = "customfield_11800"
def myCustomFieldManager = ComponentAccessor.getCustomFieldManager()
def myCustomField = myCustomFieldManager.getCustomFieldObject(myFieldId);
def myIssueManager = ComponentAccessor.getIssueManager();
def myWorkload = issue.getCustomFieldValue(myCustomField).toLong()*60*60*8;

// Update Issue
def myIssue = myIssueManager.getIssueObject(issue.getKey());
myIssue.setOriginalEstimate(myWorkload);
myIssue.setEstimate (myWorkload);
myIssue.store();

I've copied my script to my Jira home (/opt/atlassian/jira) to try it and created a post-fuction to run the script.

On a sandbox project I tried to make it works without success and strangely the catalina.out remain silent (no error).

What have I missed?

Thank you for your help!

1 answer

1 accepted

1 vote

Put the post-function first in the list.

Remove

def myIssue = myIssueManager.getIssueObject(issue.getKey());

Replace myIssue with issue. So just use the issue variable even though it's not declared in your script.
Remove the .store too, it's not necessary.
There may be other problems but try that for a start. But add some "log.warn(...)" lines so you can see that it's at least executing, and what the values are.
And don't look in catalina.out, look in <jira-home>/logs/atlassian-jira.log.

It works, thanks a lot for your help!

But I'm a bit lost... to my understanding I needed to have on object of type MutableIssue to have access to the setters (https://developer.atlassian.com/static/javadoc/jira/6.2.2/reference/com/atlassian/jira/issue/MutableIssue.html) because issue the Issue interface is read-only (https://developer.atlassian.com/static/javadoc/jira/6.2.2/reference/com/atlassian/jira/issue/Issue.html).

Also I can see in the javadoc that the store() is deprecated but I have no clue on what to use instead.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Apr 17, 2018 in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

802 views 2 19
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you