Forums

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

Selecting Assignee based on Amount

Markos Stefanou March 2, 2018

 

Trying to make this work, it doesn't produce errors but it doesn't work either.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.security.roles.ProjectRoleManager

String user;

def cfManager = ComponentAccessor.getCustomFieldManager();
def cf = cfManager.getCustomFieldObjectByName("Amount");
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)

def Initiator = projectRoleManager.getProjectRole("Initiator").getName();
def L1A = projectRoleManager.getProjectRole("Level 1 Approvers").getName();
def L2A = projectRoleManager.getProjectRole("Level 2 Approvers").getName();
def L3A = projectRoleManager.getProjectRole("Level 3 Approvers").getName();
def FM = projectRoleManager.getProjectRole("Final Manager").getName();
def COO = projectRoleManager.getProjectRole("COO").getName();

if (((int)issue.getCustomFieldValue(cf)) < 1000){
user = Initiator;
}else if (((int)issue.getCustomFieldValue(cf)) < 5000){
user = L1A;
}else if (((int)issue.getCustomFieldValue(cf)) < 10000){
user = L2A;
}else if (((int)issue.getCustomFieldValue(cf)) < 20000){
user = L3A;
}else if (((int)issue.getCustomFieldValue(cf)) < 100000){
user = FM;
}else {
user = COO;
}

// issue.setAssignee(ComponentAccessor.getUserManager().getUserByKey(user)) 
issue.setAssignee(ComponentAccessor.getUserManager().getUserByName(user))

 

 

 

problem.PNG

1 answer

0 votes
Alexey Matveev
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 2, 2018

If it is a post function, then it must be first in the list of your post functions.

Markos Stefanou March 6, 2018

Still doesn't work

Alexey Matveev
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 6, 2018

Look for errors in the log

Markos Stefanou March 7, 2018

We have 1,3m issues and every minute thousands are processed.

I've been completely unable to locate it- but probably it doesn't even produce an error. For some reason the assignee remains unassigned.

Alexey Matveev
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 7, 2018

Define a logger in your script like this

import org.apache.log4j.Loggerimport org.apache.log4j.Level  def log = Logger.getLogger("com.acme.CreateSubtask")log.setLevel(Level.DEBUG)

 

then you can find your logs by com.acme.CreateSubtask pattern

Suggest an answer

Log in or Sign up to answer