Forums

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

Set Custom Field Based on Value of Another Custom Field

Jh
Contributor
August 24, 2020

I am trying to set the value of a custom field based on another field.

Ie:

If custom field Application = Salesforce

Set custom field Additional Assignees = User1

I have a custom script-runner post script function already so I would just try to add to the existing.

So far it auto assigns the ticket if Application = Salesforce but I'd like to add an additional assignee to it.

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

//import org.apache.log4j.Level
//import org.apache.log4j.Logger

//def log = Logger.getLogger("com.acme.postfunction")
//log.setLevel(Level.DEBUG)


def applicationCf = customFieldManager.getCustomFieldObjectByName("Application")
def additionalassigneesCf = customFieldManager.getCustomFieldObjectByName("Additional Assignees")
def application = issue.getCustomFieldValue(applicationCf) as String

if (application == "Application1") {
issue.setAssigneeId("Person1")
} else if (application == "Salesforce") {
issue.setAssigneeId("Guy1")

 

1 answer

0 votes
Martin Bayer _MoroSystems_ s_r_o__
Community Champion
August 24, 2020

hi @Jh  what type of custom field is the field Additional Assignees, is it multi user picker?

Jh
Contributor
August 25, 2020

Yes, multi user picker

Martin Bayer _MoroSystems_ s_r_o__
Community Champion
August 28, 2020

@Jh sorry for late response. Problem you have to solve is that you need to set array of users as value for your Additional Assignees field, it should be something like

def userManager = ComponentAccessor.getUserManager()
def user = null
if (application == "Application1") {
issue.setAssigneeId("Person1")
user = userManager.getUserByName("Person1")
} else if (application == "Salesforce") {
issue.setAssigneeId("Guy1")
user = userManager.getUserByName("Guy1")
}
if(user){
issue.setCustomFieldValue(additionalassigneesCf, [user])
}

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.9.1
TAGS
AUG Leaders

Atlassian Community Events