Hi,
I want to populate custom fields with a specific value depending on a scripted field.
Example: Custom field = A --> text field = A1
Custom field = B --> text field = fkdfm
I tried to do it with a post function in a transition, but if someone already writes another value in the text field, this value gets overwritte. Even when no value has been scripted in the scripted field, it gets all wiped out.
So, I was thinking about a script listener, but I'm not that good of a coder. I'm stuck somewhere :-)
I'm doing something wrong here:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.UpdateIssueRequest
import com.atlassian.jira.event.type.EventDispatchOption
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def customerField = customFieldManager.getCustomFieldObject("customfield_13102")
def customer = event.getIssue().getCustomFieldValue(customerField)
def serverName = ""
if(customer == "customerA"){
serverName = "customerA.server"
} else if(customer == "customerB"){
serverName = "customerB.server"
}
if(serverName != ""){
def applicationUser = ComponentAccessor.getJiraAuthenticationContext().loggedInUser
def mutableIssue = issueManager.getIssueObject(event.getIssue().getKey())
mutableIssue.setserverName()
def updateIssueRequest = UpdateIssueRequest.builder().build()
updateIssueRequest.builder().eventDispatchOption(EventDispatchOption.ISSUE_UPDATED)
issueManager.updateIssue(applicationUser, mutableIssue, updateIssueRequest)
}
Any help is appreciated!
Kind regards,
Robin