Set default value by script runner



i have 6 custom fields. On saving an issue i want to store the sum of this fields as timetracking original estimate.

I add an behavior with following code in init:

def field = getFieldById('timetracking_originalestimate');
def fe_1 = getFieldById('customfield_12722').getValue();
def fe_2 = getFieldById('customfield_12723').getValue();
def fe_3 = getFieldById('customfield_12724').getValue();
def be_1 = getFieldById('customfield_12725').getValue();
def be_2 = getFieldById('customfield_12726').getValue();
def be_3 = getFieldById('customfield_12727').getValue();

field.setFormValue(Math.round((Double.parseDouble((String) fe_1) + Double.parseDouble((String) fe_2) + Double.parseDouble((String) fe_3) + Double.parseDouble((String) be_1) + Double.parseDouble((String) be_2) + Double.parseDouble((String) be_3)) * 60 * 60));

Nothing happend.


Thanks for your help

1 answer

Hi Thorsten,

i dont know the methods you are using but maybe this example helps you,

this is code we have in use for an event Listener that sets an custom field value:

import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.ApplicationUser
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import java.sql.Timestamp
import com.atlassian.jira.event.type.EventDispatchOption

def issueTypeId = issue.getIssueTypeId()
IssueManager issueManager = ComponentAccessor.getIssueManager()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()

JiraAuthenticationContext jiraAuthenticationContext = ComponentAccessor.getJiraAuthenticationContext();
ApplicationUser user = jiraAuthenticationContext.getLoggedInUser()

CustomField technikerTerminCF = customFieldManager.getCustomFieldObjectByName("Techniker-Termin")
Timestamp technikerTermin = issue.getCustomFieldValue(technikerTerminCF);

MutableIssue mutableIssue = issueManager.getIssueObject(issue.getId());
mutableIssue.setCustomFieldValue(technikerTerminCF, technikerTermin)
issueManager.updateIssue(user, mutableIssue, EventDispatchOption.ISSUE_UPDATED, false)



Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,293 views 14 20
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot