Snippets

Adaptavist Auto assigning a user based on a combination of two different custom fields

You are viewing an old version of this snippet. View the current version.
Revised by Mark McCormack 3ea8ca0
// This was a request from a potential customer
// The requirements were that the price was entered as a number
// and the Third Party Relationship was chosen from a single select list
// then the Assignee is assigned automatically as part of a create issue transition post function
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField

def projectComponentManager = ComponentAccessor.getProjectComponentManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def userUtil = ComponentAccessor.getUserUtil()
def numberCf = customFieldManager.getCustomFieldObjectByName("Purchase Amount")
def selectCf = customFieldManager.getCustomFieldObjectByName("Third Party Relationship")
def purchaseAmount = issue.getCustomFieldValue(numberCf) as double
def thirdPartyRelationship = issue.getCustomFieldValue(selectCf)

if (purchaseAmount < 5000) {
    issue.setAssigneeId('user1') // Change user1 to the appropriate user in JIRA
} else if ((purchaseAmount >= 5000) && (purchaseAmount <= 10000)) {
    if (thirdPartyRelationsip == 'value A') {
        issue.setAssigneeId('user1') // Change user1 to the appropriate user in JIRA
    } else {
        issue.setAssigneeId("user2") // Change user2 to the appropriate user in JIRA
    } 
} else {
    issue.setAssigneeId("user2") // Change user2 to the appropriate user in JIRA
}
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.