Set Assignee to match Parent's Custom Field Value

Michael Romrell March 9, 2015

I'm using Jira and the Script Runner plugin to Create a sub-task on transition. That's all working well. However, I cannot seem to set the 'Assignee' of the Subtask to match the value of the 'Project Manager' listed on the parent (which is a custom field). Below is what I am using, But it does not work. What is the correct way to write this?:

issue.assignee = transientVars["originalissueobject"].cfValues['Project Manager']


 

I've Seen similar posts like this and this but nothing that shows how to Set the Assignee of a Sub-task based on the the Custom Field Value of the Parent Issue.  Thanks for you Help!

2 answers

1 accepted

0 votes
Answer accepted
Michael Romrell March 11, 2015

@Alejo Villarrubia [Adaptavist], you were definitely on the right track. I wasn't able to get your script to work, but I found a very similar script here that worked perfectly! Thank you so much for your help!

import com.atlassian.jira.user.ApplicationUsers
 
cfParent = customFieldManager.getCustomFieldObjectByName('Project Manager')
parentMyFieldValue = transientVars["issue"].getCustomFieldValue(cfParent)
issue.setAssignee(ApplicationUsers.toDirectoryUser(parentMyFieldValue))
1 vote
Alejo Villarrubia [Adaptavist]
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.
March 10, 2015

Hi @Michael Romrell,

Can you try this out?

import com.atlassian.jira.component.ComponentAccessor

def projectManagerCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Project Manager")
def projectManager = issue.getCustomFieldValue(projectManagerCF)

if (projectManager) {
    issue.setAssigneeId(projectManager)
}

Hope it helps

Michael Romrell March 10, 2015

Thank you for your reply!! To Do that, I Assume that I would add this as a post function on the "Create" Transition of my sub task (Via Script Runner's). The only issue is that I don't have direct access to upload my own script files (That requires lots of bureaucracy). Is there another way I can try out your script?

Alejo Villarrubia [Adaptavist]
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.
March 10, 2015

No problem. There is no need to upload the script actually. You can simply replace the code that your instance already has in the "Additional issue actions" with the one I shared.

Michael Romrell March 11, 2015

Unfortunately, It isn't working (It won't create a subtask with that script in place). To be verify that I'm adding it to the right place. The script is going in the "Additional Issue Actions" field of Script Runner's "Create Sub-Task" Post Function which is tied to the parent transition. Is that correct? ---- I should also mention that the plugin, MISC JIRA Worflow's "Copy Value From Other Field" Post function performs the exact task that I need, however, I cannot get that, or any, post function to work on the subtask's "Create" Transition. but on any other subtask transition, that particular post function will actually assign the Subtask based on the custom field value of the parent.

Suggest an answer

Log in or Sign up to answer