Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Set assignee field based on a condition

Paul Emich January 12, 2016

How am I able to set the assignee field of an issue based on a condition when a transaction is fired?

What I want to achieve is the following "condition":

projectRoleUsers = project.getUsersInRole("Rolename");
if(currentUser() in projectRoleUsers) {
   newAssignee = "unassigned";
}
else {
  newAssignee = projectRoleUsers.first();
}
issue.assignee = newAssignee;

I tried to achieve this by doing the following:

  • Assign the issue to the default user from the Rolename role. 
  • The value of field Assignee of the current issue will be set to null (replacing existing values).
    • With condition: return (currentValue == currentUser);

 

This however doesn't work as I want it to. Basically the Role can only be filled with one user (or empty). On this transition the assignee always needs to be set to that user unless the person executing the transition is the same user.

Hopefully someone can tell me how to set this up correctly smile

2 answers

0 votes
Vasiliy Zverev
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, 2016

This code will unassign an issue when curUser = assignee:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.user.ApplicationUser

ApplicationUser curUser = ComponentAccessor.jiraAuthenticationContext.getUser();

if(curUser == issue.getAssignee())
    issue.setAssignee(null)

ComponentAccessor.getIssueManager().updateIssue(curUser, issue, EventDispatchOption, false)

Use it for script postfunction. Hope it will help.

0 votes
Vasiliy Zverev
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, 2016
  1. Is it full code or just an idea to do
  2. You do not store changes into database, since no update
  3. I do not understand an algorithm to get assignee. 
    1. What does it mean default user from project role. It is not defined value, because project role if filled by users and groups. We can speak that current user is into project role. 
    2. If you want to get unassugned issue you should use issue.assignee = null

 

Paul Emich January 12, 2016
  1. This is just an idea of what I want to achieve
  2. I had set these actions for the transition in my workflow, purging field or filling it with the user from the specified role works perfectly, however I want to add another condition smile
  3. With the default user for the project role I mean the user who we have assigned for the role. This is only one user, not a group or multiple users.


Here a quick view of the situation how it should be;

  • Each project has one specific user assigned for "Code review" (Role for the project).
  • Once a issue goes from Development to "Code review" we want this issue to be assigned automatically to the user who belongs to the "Code review" role for that specific project, unless that person is the one doing the transition.

The following works perfectly fine for automatically assigning the right user to the issue:
img01.png

From this point all I need is to check whether that person is the "currentUser()", if so the assignee should be assigned to "unassigned".

Rishit December 1, 2016

Hey Paul,

As per the above description, i have a smillar question.

suppose i have a 'if condition' how we are going to right that condition for 'Code Review'

 

if ( Customfiedtype = Desktop||Laptop )  Assignee = code review

Please help me out on this..

 

 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events