Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

how to change the assignee value depends upon the custom field value

rTrack Support June 8, 2016

hi ,

i need to set the default assignee based on the custom field value . could you please help on this .

ex:

custom field value contains :a,b,c,d

if a choose need to assign to the user a in the same post function 

if i choose b then need to change as b user .

 

here we are using a single issue to look at various teams . so we have to move the tickets with the internal status as custom field value . pls help on this .

we will allocate to the user based on the field value only .

 

Thanks in advance .

 

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Mahesh S
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 8, 2016

First of all, I hope you are using a User Picker custom field having a,b,c and d values. However, you can try this following step.

In the workflow post function, you will get a built-in post function 'Copy custom field values', if you have script runner plugin. Here, you can provide the source field and target field for copying the values.

rTrack Support June 8, 2016

Hi Mahesh,

i am having the custom field value with team names .

if i choose team a then need to set to some user in the post function

if i choose team b then need to set to different user by using the post function.

 

rTrack Support June 8, 2016

If it is possible with script runner pls suggest the methods how to assign the issue based on the custom field value .

Mahesh S
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 8, 2016

Please try this script and let me know the results. Sorry, I couldn't test and provide you, since I am away from my work station.

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.user.util.DefaultUserManager
import com.atlassian.crowd.embedded.api.User
 
userManager = (UserManager)  ComponentAccessor.getUserManager()
MutableIssue issue = issue
IssueManager issueManager = ComponentAccessor.getIssueManager()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField mycustomfield = customFieldManager.getCustomFieldObjectByName("customfield_Name")
String mycustomfieldValue = (String) issue.getCustomFieldValue(mycustomfield)
if(mycustomfieldValue != null)
{
	if(mycustomfieldValue.equals("a")){
		User usera = userManager.getUser('userABC')
		issue.setAssignee(usera)
	}
	if(mycustomfieldValue.equals("b")){
		User userb = userManager.getUser('userXYZ')
		issue.setAssignee(userb)
	}
}
rTrack Support June 8, 2016

hi thanks mahesh ..

shall i need to paste this script in the post function directly  or else.. 

Mahesh S
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 8, 2016

yes, you can use this script directly by making these changes,

  • customFieldManager.getCustomFieldObjectByName("customfield_Name") - Replace "customfield_Name" with your customfield name.
  • mycustomfieldValue.equals("a") - Here, "a" is your first value of customfield.
  • User usera = userManager.getUser('userABC') - Here, 'userABC' is your new assignee value.

    Similarly add the other values as well, in respective if loops.
1 vote
Sofya November 21, 2016

So close! When I copy this script to my post-function

I get two errors:

  1. "unable to resolve class UserManager" for this line:
    userManager = (UserManager)  ComponentAccessor.getUserManager()

      2. "unable to resolve class IssueManager" for this line:

     IssueManager issueManager = ComponentAccessor.getIssueManager()

 

Any ideas?

Thank you.

Sebastian Gomez April 29, 2019

I am getting the same error error.PNG

TAGS
AUG Leaders

Atlassian Community Events