Workflow Post Function - Assign PM Role Based on Custom Field

Dusty Brossart June 8, 2016

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 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

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.

MattS
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 15, 2016

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.

Dusty Brossart June 15, 2016

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

0 votes
Dusty Brossart June 8, 2016

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
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

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
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

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

Dusty Brossart June 10, 2016

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
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 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