Workflow Post Function - Assign PM Role Based on Custom Field


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.



2 answers

1 accepted

0 votes
Accepted answer

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)

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.

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?

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.

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
Community showcase
Published Jan 08, 2019 in Jira

How to Jira for designers

I’m a designer on the Jira team. For a long time, I’ve fielded questions from other designers about how they should be using Jira Software with their design team. I’ve also heard feedback from other ...

1,084 views 4 9
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