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

Deleted user February 12, 2015

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

0 votes
JamieA
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.
February 12, 2015

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.

Deleted user February 13, 2015

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!

Deepali Bagul July 19, 2017

Hello @[deleted] 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
TAGS
AUG Leaders

Atlassian Community Events