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

Francisco Ayala Bocardo January 8, 2018

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

1 vote
Answer accepted
Jenna Davis
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.
January 8, 2018

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

Francisco Ayala Bocardo January 9, 2018

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

Jenna Davis
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.
January 12, 2018

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

Francisco Ayala Bocardo January 12, 2018

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.

Jenna Davis
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.
January 17, 2018

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)
Francisco Ayala Bocardo January 17, 2018

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

Jenna Davis
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.
January 17, 2018

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 Sign up to answer