Set default value by script runner

Hi,

 

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

This widget could not be displayed.

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.security.JiraAuthenticationContext
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)

 Cheers

Jens

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Aug 06, 2018 in Jira Service Desk

A is for Activate: Share your top Jira Service Desk onboarding tips for new users!

Hi, everyone! Molly here from the Jira Service Desk Product Marketing Team :).  In the spirit of this month's  august-challenge, we're sourcing stories of Jira Service Desk activation fro...

575 views 25 15
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