I am attempting to copy a custom field called "Customer" to the Security Level field in a workflow post-function using Jira Server 8.12. I have already made all the security levels to mimic the options in customer, but I cannot see a way to identify the security levels by name rather than ID. I was hoping to be able to call up a list of security levels in the script, match the security level by name, and use the associated ID to populate the request. Is this possible? Below is a rough idea of what I am trying to do:
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.security.IssueSecurityLevelManager
import com.atlassian.jira.issue.security.IssueSecuritySchemeManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.security.IssueSecurityLevel
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.event.type.EventDispatchOption
def indexingService = ComponentAccessor.getComponent(IssueIndexingService.class)
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issue = event.issue as MutableIssue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Customer'}
def cfvalue = issue.getCustomFieldValue(cf).toString()
issue.setSecurityLevelByName(cfValue)