Change Assignee in Post Function using a Custom Field Value from a different Ticket

Hello,

I would like to know if changing the assignee in a post function using the value from a custom field that is in a different issue (and project) can be done. I was reviewing using JQL query (Execute a JQL Query), but I am not sure how to extract the value that is a user, and then use that value to set the assignee on the issue that is being transitioned. 

Here's the case: I have a ticket that contains multiple users in multiple custom fields (i.e. AAA-1, custom fields A - Z). Then, I have several projects (BBB-ZZZ) and all of these projects use the same workflow. So whenever I perform a transition in these projects, I would like for assignee to be updated with the value from AAA-1 - Custom Field A. The situation is that user for Custom Field A in project AAA will be different every week, so the post function will always assign the issue in the post function to a different user. 

Given this the following options cannot be used:

  • Fixed user in the post function
  • Project Role assignation

Let me know if there's a way to do this either with Script Runner or CLI Actions.

Regards,

Francisco Ayala

1 answer

1 accepted

Hello, 

You should be able to do this, but I'm not entirely sure of what you're describing. I think you could just create a post function that gets the value from your custom field and sends it to your issue (in the different project). You can check out the IssueManager class for a bit more information on how to get an issue if you're not sure how to do that.

I'm a bit confused on how you're wanting to assign people to what issue though, could you go into a bit more detail or give me a more descriptive use case so I can give you more valuable information?

Jenna

Hi Jenna,

The case is the following. I have ticket A-1 (Project A), in which I have a custom field called "Lead" (Custom field is a Single User) and the value is my username. On the other hand I have several projects (Project B - Z) for which all are sharing the same workflow for the same issue type. In a specific transition inside this shared workflow for projects B - Z I want the assignee to be changed as part of a post function to my username (value of "Lead" in project A). 

I hope is clearer now, thanks.

Francisco Ayala

Okay, I think you could do something similar to this (roughly):

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

def issueManager = ComponentAccessor.issueManager
def issue = issueManager.getIssueByCurrentKey("A-1")
def projectLead = issue.getProjectObject().projectLead

MutableIssue mutableIssue = issue as MutableIssue
mutableIssue.setAssignee(projectLead)

I didn't test this out directly, so if something isn't working please let me know. 

Jenna

Hi Jenna,

I gave a try to your script (modified some things) and it does not work.

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.project.Project
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor

def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("A-1")
def projectLead = issue.getProjectObject().getProjectLead().getKey()

MutableIssue mutableIssue = issue as MutableIssue
mutableIssue.setAssigneeId(projectLead)

If I delete the part of "Def issue" and "MutableIssue" just leaving the "def projectLead" and "set.AssigneeId(ProjectLead) it does work assigning it for the project lead of current project. So the problem is obtaining the value from the other project using the "A-1" and applying it to current ticket.

Try this out instead, I misread a portion of your example:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

def issueManager = ComponentAccessor.issueManager
def customFieldManager = ComponentAccessor.customFieldManager
def retrieveIssue = issueManager.getIssueByCurrentKey("A-1")
def lead = customFieldManager.getCustomFieldObject("Lead").getValue(retrieveIssue)

MutableIssue mutableIssue = issue as MutableIssue
mutableIssue.setAssignee(lead)

Hi Jenna,

I was able to make it work both ways, thanks a lot for your help. Below you can find the scripts I used.

Project Lead

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.project.Project
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor

def retrieveissue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("A-1")
def projectLead = retrieveissue.getProjectObject().getProjectLead().getKey()

MutableIssue mutableIssue = issue as MutableIssue
mutableIssue.setAssigneeId(projectLead)

 

Custom Field "Lead"

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser

def issueManager = ComponentAccessor.issueManager
def customFieldManager = ComponentAccessor.customFieldManager
def retrieveIssue = issueManager.getIssueByCurrentKey("RM-2")
def lead = customFieldManager.getCustomFieldObjectByName("Lead QE")
def leaduser = retrieveIssue.getCustomFieldValue(lead) as ApplicationUser

MutableIssue mutableIssue = issue as MutableIssue
mutableIssue.setAssignee(leaduser)

 

Regards,

Francisco Ayala

Great! Glad it's working for you. :)

If you have any more trouble with it feel free to let me know. 

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,855 views 12 18
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot