Snippets

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

Created by Mark McCormack last modified
// 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

def customFieldManager = ComponentAccessor.getCustomFieldManager()
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 (thirdPartyRelationship == '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 { // purchaseAmount > 10,000 and thirdPartyRelationship should be irrelevant
        issue.setAssigneeId("user2") // Change user2 to the appropriate user in JIRA
    }
}

Comments (0)

HTTPS SSH

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