Set customfield to specific value depending on another customfield


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?


2 answers

0 vote

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:

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


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 { == "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 { == "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)

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Apr 17, 2018 in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

795 views 2 19
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