Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Set default value by script runner

traperto GmbH
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 6, 2017

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

0 votes
Jens Kisters __SeibertSolutions
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 8, 2017 edited

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
TAGS
atlassian, loom, loom for training, loom for teaching, video training, async learning, online education, screen recording, loom tutorials, loom use cases, atlassian learning, team training tools, instructional video, virtual training tools

🛗 Elevate Your Training and Enablement with Loom

Join us June 26, 11am PT for a webinar with Atlassian Champion Robert Hean & Loom’s Brittany Soinski. Hear tips, stories, and get your burning questions answered. Learn how Loom makes training and enablement easier. Don’t miss it!

Register today
AUG Leaders

Atlassian Community Events