Is it possible to copy a text field value into a user field? Using Script Runner or any other way

We have a need for a cascading group/user field in our workflow, however I have not found a add on that does this. By cascading group user field I mean:

Be able to select a JIRA group that then shows a user field that is filtered for only the users in that group. A drop down choice of users instead of a the intuitive type would be the best. Other requirement would be to be able to filter the group field for only certain groups.

 

Since I haven't found such an add on, my work around I've been playing with is to use a normal cascading choice field that has the values of the groups and names of users in those groups in the field. (Those only about 10 groups needed so this would be pretty easy to manage)

Then with a script runner custom script I am pulling the values out of the first cascading field value (groups) and the second part of the cascading field value (users) and setting those to 2 seperate a text fields.

From there I'd like to be able to set the assignee field with that "user" text fields value. I was wondering if anyone has done something like this. Note the "user" text field is filled in with the Display Name.

1 answer

It's not that straightforward to get the user object from the displayname, and apart from anything else they are not unique. Probably the best you can do is iterate all users and find the one with the matching display name.

I tried to do that using this script. I didn't think the getDisplayableNameSafely was the right thing to use but I didn't find anything else that seemed like it would let me query by the display name(I was testing by trying to set a custom user field before I tried to set the assignee)

 

import com.atlassian.jira.issue.CustomFieldManager

import com.atlassian.jira.ComponentManager

import com.atlassian.jira.issue.fields.CustomField

import com.atlassian.jira.issue.ModifiedValue

import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

import com.atlassian.jira.issue.util.IssueChangeHolder

import com.atlassian.crowd.embedded.api.User

import com.atlassian.jira.security.groups.GroupManager

 

def sourceFieldName = "customfield_10253"

def targetFieldName = "customfield_10256"

 

ComponentManager componentManager = ComponentManager.getInstance()

CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()

CustomField customFieldSrc = customFieldManager.getCustomFieldObject(sourceFieldName)

CustomField customFieldTarget = customFieldManager.getCustomFieldObject(targetFieldName)

String sourceFieldVal = issue.getCustomFieldValue(customFieldSrc).toString()

User[] users = componentManager.getUserUtil().getUsers().each().getDisplayableNameSafely(sourceFieldVal)

 

User test = users[0].getEmail()

 

IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();

customFieldTarget.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customFieldTarget), test), changeHolder)

 

Any help on where I went wrong would be amazing!

Hello @Kirsten Cutler did you ever got the solution . I am trying to do similar for watchers as watchers are not working through CSV. I trying using script runner.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Wednesday in Jira

Make your Atlassian Cloud products more secure: our NEW admin security guide

Hey admins! I’m Dave, Principal Product Manager here at Atlassian working on our cloud platform and security products. Cloud security is a moving target. As you adopt more products, employees consta...

45 views 0 2
Read article

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