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 Sign up to answer
Community showcase
Posted Oct 16, 2018 in Jira

Looking for anyone who made the switch to Data Center

The Jira Marketing team is putting together an ebook on migrating to Data Center. We're looking for pro tips on how you staffed your project team and organized your Proof of Concept. Share yo...

1,379 views 17 10
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