So I am trying to automate the creation of a new tickets based on the end date of a resolved ticket using the Escalation service in script runner.
The JQL is project = vc AND issuetype = Story AND "Due Date" = -199d
The new issue is being created and linked to the resolved issue so all good there, however I want to populate a set of custom fields in the new ticket, in the script I'm testing with a field called 'Accessibility' or object "customfield_11008" which is a radio button selection options 'yes' or 'no'. I would like to set this to yes. However cannot get this to work.
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager
//origin issue - result of JQL
def issueManager = ComponentAccessor.getIssueManager()
def issueKey = issue.getKey();
def issueID = issue.getId();
def issueTypeName = issue.getIssueType().name
def issueStatusName = issue.getStatus().getSimpleStatus().getName()
log.setLevel(org.apache.log4j.Level.DEBUG);
log.debug "JC Key = $issueKey"
log.debug "JC TYPE = $issueTypeName"
log.debug "JC STATUS = $issueStatusName"
log.debug "JC ID = $issueID"
log.debug "JC Reporter = $issue.reporter.name"
def issueService = ComponentAccessor.issueService
def projectManager = ComponentAccessor.projectManager
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
def IssueLinkManager = ComponentAccessor.getIssueLinkManager()
//target project&issue
def issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.with {
projectId = projectManager.getProjectObjByKey("EGA").id
summary = issue.summary
issueTypeId = "10001"
reporterId = user.name
}
def validationResult = issueService.validateCreate(user, issueInputParameters)
assert !validationResult.errorCollection.hasAnyErrors()
//new issue created
def issueResult = issueService.create(user, validationResult)
def newIssueID = issueResult.getIssue().getId()
def optionsManager = ComponentAccessor.getComponent(OptionsManager)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObject("customfield_11008")
def fieldConfig = cf.getRelevantConfig(issue)
def option = optionsManager.getOptions(fieldConfig).getOptionForValue("Yes", null)
issue.setCustomFieldValue(cf, option)
log.debug "JC NEWID = $newIssueID"
log.info "Issue created: ${issueResult.issue}"
//link to origin issue
IssueLinkManager.createIssueLink(newIssueID, issueID, (Long)10003, (Long)0L, currentUser)