Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

ScriptRunner Behavior - Setting value of user picker

Hello All

I have to read user picker field from 1 issue and set it in other. I am getting error in step-3 and not sure if step-4 is required, if so how to do it.


Step-1: Getting other issue to read user info from current issue. In current  issue other issue is picked in a issue picker

def relatedIssue = ComponentAccessor.issueManager.getIssueByCurrentKey(issuePickerFieldValue as String)


Step-2: Getting user field from other issue, if not set in current issue

def relatedCustomUserFieldValue = relatedIssue.getCustomFieldValue("My User")


Step-3: Populate issue picker in the current issue ( Error on line 3)

def myPM = getFieldByName(userFieldName[0])
def pmuser = userManager.getUserByKey(relatedCustomUserFieldValue)
setCustomFieldValue(myPM,pmuser)  // Error says no matching method


Step-4: Need to update the current issue, is it required

I know ScriptRunner console equivalent code as below, is there equivalent for behavior?

ComponentAccessor.getIssueManager().updateIssue(currentUser, issue, EventDispatchOption.ISSUE_UPDATED, false)



Please let me know 


2 answers

1 accepted


Thanks for the response. Here is the code I wrote in the Behavior. When I select "Related Issue" in the issue picker field, I expect PM field to be populated.

PM field is not populated. I also do not see log lines in atlassian-jira.log

Please let me know if you see any issue in the code, and why I do not see log lines.

 Behavior is mapped to proper project and issuetype


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.datetime.DateTimeFormatter
import com.atlassian.jira.issue.customfields.impl.DateTimeCFType
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.ApplicationUser
import com.onresolve.jira.groovy.user.FieldBehaviours
import org.apache.log4j.Logger
import org.apache.log4j.Level
import groovy.transform.BaseScript
import com.atlassian.jira.event.type.EventDispatchOption

@BaseScript FieldBehaviours fieldBehaviours

// Set the log level
def log = Logger.getLogger(getClass())
log.debug("******************** at top *****************")

// Get the product value
final issuePickerFieldName = "Related Issue"
def issuePickerField = getFieldByName(issuePickerFieldName)
def issuePickerFieldValue = issuePickerField.value
if (!issuePickerFieldValue) {

// Get reference to issue from where we need to pick PM value
def relatedIssue = ComponentAccessor.issueManager.getIssueByCurrentKey(issuePickerFieldValue as String)
if (!relatedIssue) {
log.error("Could not find issue with key $issuePickerFieldValue")
log.debug("""Selected Issue Key = ${relatedIssue.key}
Selected Issue Summary = ${relatedIssue.summary}""")

// Get the PM name to set
def customFieldManager = ComponentAccessor.customFieldManager
final userFieldName = 'PM'
def myUserField = customFieldManager.getCustomFieldObjectsByName('PM')[0]
def relatedCustomUserFieldValue = (myUserField ? relatedIssue.getCustomFieldValue(myUserField) : null)

def description = "Defaulted value set from related issue ${relatedIssue.key}"

// Populate user picker field
.setFormValue((relatedCustomUserFieldValue as ApplicationUser).name)


Suggest an answer

Log in or Sign up to answer

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you