Set Assignee to match Parent's Custom Field Value

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

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

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

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?

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.

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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

758 views 2 19
Join discussion

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