Set customfield to specific value depending on another customfield

Ulrich Schreck June 10, 2014

Hi,

once me again. during a workflow validation I need to set a customfield to a specific value when a another custom field b is not empty.

How can I accomplish that with a groovyscript?

Thanks

2 answers

0 votes
Paresh Gandhi
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.
June 26, 2014
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.bc.issue.IssueService.UpdateValidationResult
import com.atlassian.jira.bc.issue.IssueService.IssueResult
import java.sql.Timestamp
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.ComponentManager 
import com.atlassian.jira.issue.CustomFieldManager 
import com.atlassian.jira.issue.fields.CustomField

def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == "fromwhich you want to get the value"}
def cfgvalue = issue.getCustomFieldValue(cf)
 
MutableIssue issue = event.issue
ComponentManager componentManager = ComponentManager.getInstance()
def customFieldManager = componentManager.getCustomFieldManager()
IssueManager issueManager = componentManager.getIssueManager()
def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Custome field to be set"}
//def date1 = new Timestamp(new Date().getTime())	// use this one if field is date type		
def newvalue = "abc
issue.setCustomFieldValue(cf, newvalue)
User currentUserObj = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()	
issueManager.updateIssue(currentUserObj, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
issue.store()

0 votes
Benito Picarelli
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 25, 2014

Helo Ulrich,

Apparently you can achieve that with the script runner plugin. I found the following answer, where people are discussing how to do that:

https://answers.atlassian.com/questions/178183/display-a-custom-field-values-based-on-value-of-another

Please take a look and let me know if it helps you out.

Cheers.

Suggest an answer

Log in or Sign up to answer