Workflow Post Function - Assign PM Role Based on Custom Field

Hello,

I'm having an issue with a workflow and getting it to do what I want.  I have set up an issue that has a custom project field selector.  My goal is to have issue be assigned to the someone in the PM role of the project that is selected in the project selection custom field.  I'm sure it's possible through some scripting, but I'm unfamiliar with JIRA's language.  Any help is greatly appreciated.

Thanks!

-Dusty

2 answers

1 accepted

0 vote
Mahesh S Community Champion Jun 08, 2016

Please try this script with necessary changes.  Here,

customFieldManager.getCustomFieldObjectByName("customfield_Name") - Replace "customfield_Name" with your customfield name.

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")
def mycustomfieldValue = (ApplicationUser)issue.getCustomFieldValue(mycustomfield)
issue.setAssignee(mycustomfieldValue)

This assigns the issue to the user mentioned as the customfield value.

I think the OP wants a script to get the selected Project object from the custom field, then get one of the users in the PM role in that project, then set the assignee to that user.

Matt is correct on what I'm after.  Is something like this possible?

Thanks for the quick reply!

The custom field is actually a Project selection and I'm wanting to assign the issue to someone in the PM role of the project selected in that custom field.

Mahesh S Community Champion Jun 08, 2016

Basically, you were using a Project selection field, but it carries PM user values. how did you configured those values to the custom field?

So, you manually added those selection values for the field. The project selection custom field's value is not user type. Is my understanding correct?

Mahesh S Community Champion Jun 08, 2016

Can you please provide an example on the field values and the situation?

Sorry for not responding sooner, I'm apparently limited to 2 posts in 24 hours.

It's a Project Picker (single project) custom field, so I didn't manually add the projects.  Yep, it's not a user type.  There are post functions that allow you to assign the issue to the PM role, but that would be for the current project.  I need to somehow get the PM role from that custom field and assign it that way. Hopefully that makes sense.  Let me know if you need any more info.

Mahesh S Community Champion Jun 10, 2016

Basically, you need to get the custom field value and convert it to user type based on multiple conditions. Then, it has to be assigned to that respective PM. Is my understanding right? If else, please explain the situation with an example including the field values.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Monday in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

700 views 6 13
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