Hello,
I have jira data center v9.12.7, and i create a script runner: when create a issue son, fill Affected Versions from the issue dad.
When user create an issue type epic, will be create sub-tasks, and in type "Configuration" i want fill "setAffectedVersionIds", but the sub-task don't stay filled why could you helpme please ?
In logs apears filled:

- file scriptrunner "CreateStories.groovy"
import com.atlassian.jira.bc.issue.IssueService import com.atlassian.jira.config.IssueTypeManager import com.atlassian.jira.issue.IssueInputParameters import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.event.type.EventDispatchOption import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.issuetype.IssueType import com.atlassian.jira.user.ApplicationUser import com.atlassian.jira.issue.customfields.option.Options import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.customfields.manager.OptionsManager import com.atlassian.jira.issue.fields.CustomField import pt.i2s.jira.functions.CreateIssue import org.apache.log4j.Logger import org.apache.log4j.Level def log = Logger.getLogger("pt.i2s.jira.postfunction.CreateStories") log.setLevel(Level.DEBUG) ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() log.info("Aplication user") CustomFieldManager customFieldManager = ComponentAccessor.getComponent(CustomFieldManager); log.info("CustomFieldManager") OptionsManager optionsManager = ComponentAccessor.getComponent(OptionsManager); log.info("Options manager") CustomField storyType = customFieldManager.getCustomFieldObjectsByName("Story Type")[0] log.info("Strory type") CustomField epicLink = customFieldManager.getCustomFieldObjectsByName("Epic Link")[0] log.info("Epic Link") Options options = optionsManager.getOptions(storyType.getConfigurationSchemes().first().getOneAndOnlyConfig()); log.info("Options options") IssueService issueService = ComponentAccessor.getIssueService() log.info("Issue service") if(((String)issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectsByName("Epic Type")[0])) == "Functional Feature" || ((String)issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectsByName("Epic Type")[0])) == "Technical Feature") { log.info("ENTREI NO IF CRIACAO DE ISSUES") CreateIssue.createIssue("Analysis", user, storyType, options, issueService, epicLink, issue ) log.info("CRIAR ISSUE ANALYSIS") CreateIssue.createIssue("Development", user, storyType, options, issueService, epicLink, issue ) log.info("CRIAR ISSUE DEV") CreateIssue.createIssue("TestsSpec", user, storyType, options, issueService, epicLink, issue ) log.info("CRIAR ISSUE TSTSPEC") CreateIssue.createIssue("TestsExec", user, storyType, options, issueService, epicLink, issue ) log.info("CRIAR ISSUE TSTEXEC") CreateIssue.createIssue("Documentation", user, storyType, options, issueService, epicLink, issue ) log.info("CRIAR ISSUE DOC") CreateIssue.createIssue("Configuration", user, storyType, options, issueService, epicLink, issue ) log.info("End creating stories") } if(((String)issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectsByName("Epic Type")[0])) == "Functional Feature" || ((String)issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectsByName("Epic Type")[0])) == "Technical Feature") { log.info("ENTREI NO IF EPIC TYPE TECHNICAL/FUNCTIONAL FEATURE") if(((String)issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectsByName("Security Requirements")[0])) == "Yes" ){ log.info("ENTREI NO IF SECURITY REQUIREMENTS") CreateIssue.createIssue("Security", user, storyType, options, issueService, epicLink, issue ) } }
- file scriptrunner "CreateIssue.groovy"
package pt.i2s.jira.functions import com.atlassian.jira.bc.issue.IssueService import com.atlassian.jira.config.IssueTypeManager import com.atlassian.jira.issue.IssueInputParameters import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.event.type.EventDispatchOption import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.issuetype.IssueType import com.atlassian.jira.user.ApplicationUser import com.atlassian.jira.issue.customfields.option.Options import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.customfields.manager.OptionsManager import com.atlassian.jira.issue.fields.CustomField import org.apache.log4j.Logger import org.apache.log4j.Level import com.atlassian.jira.issue.customfields.option.Option; class CreateIssue{ static boolean createIssue(def type, ApplicationUser user, CustomField storyType, Options options, IssueService issueService ,CustomField epicLink, Issue issue){ def log = Logger.getLogger("pt.i2s.jira.functions.CreateIssue") log.setLevel(Level.DEBUG) log.info("Entrou Create Issue") //functional area //affects version //epic type CustomFieldManager customFieldManager = ComponentAccessor.getComponent(CustomFieldManager); CustomField lob = customFieldManager.getCustomFieldObjectsByName("LOB")[0] log.info("CRIA LOB") def lobValue = (Option)issue.getCustomFieldValue(lob) log.info("CRIA APPLICATION") CustomField software = customFieldManager.getCustomFieldObjectsByName("Application")[0] def softwareValue = (Option)issue.getCustomFieldValue(software) //log.info("APPLICATION CUSTOM FIELD: " + softwareValue.getValue()) //CustomField functionalArea = customFieldManager.getCustomFieldObjectsByName("Functional Area")[0]; //CustomField affectsVersion = customFieldManager.getCustomFieldObjectsByName("Affects Version/s")[0]; String selectedOptions = options.findAll { it.value == type }.collect { it.optionId }.first() log.info("SELECIONOU OPÇÕES") issue.getComponents() def myComponents=[]; for(component in issue.getComponents()){ log.info("A ITERAR NOS COMPONENTES") myComponents.add(component.getId() as long); } log.info("ITEROU NOS COMPONENTES") IssueInputParameters issueInputParameters = issueService.newIssueInputParameters(); log.info("BEGIN PARAMETERS") issueInputParameters .setProjectId( issue.getProjectObject().id ) .setSummary( issue.summary) .setDescription(issue.description) .setIssueTypeId("10001") .setReporterId(user.getName()) .setComponentIds(myComponents as Long[]) .addCustomFieldValue(storyType.id, selectedOptions) .addCustomFieldValue(epicLink.id, issue.key) log.info("END PARAMETERS") if(lobValue != null ){ log.info("VERIFICA LOB") issueInputParameters.addCustomFieldValue(lob.id, String.valueOf(lobValue.optionId)) } /* if(softwareValue != null){ log.info("VERIFICA SOFTWARE VALUE") issueInputParameters.addCustomFieldValue(software.id, String.valueOf(softwareValue.optionId)) log.info("SOFTWARE OPTION ID: " + String.valueOf(softwareValue.optionId)) } */ if(type == "Security"){ log.info("VERIFICA SECURITY") issueInputParameters.setAssigneeId("psantos") } if(type == "Configuration"){ log.info("VERIFICA CFG") issue.getAffectedVersions() def myAffectedV=[]; for(version in issue.getAffectedVersions()){ log.info("A ITERAR NOS AFFECTED VERSIONS") myAffectedV.add(version.getId() as long); log.info("affectedVersion: " + version.getName() + " Id: "+version.getId()); } log.info("ITEROU NOS AFFECTED VERSIONS") issueInputParameters.setAffectedVersionIds(myAffectedV as Long[]) } log.info("CRIA VALIDATION RESULT") IssueService.CreateValidationResult createValidationResult = issueService.validateCreate(user, issueInputParameters) log.info("ITERA NO VALIDATION RESULT") createValidationResult.getErrorCollection().getErrors().each{ key, value -> log.error( key +" : "+value) } if (createValidationResult.isValid()) { log.info("VALIDATION RESULT VALID") IssueService.IssueResult createResult = issueService.create( user, createValidationResult) log.info("CREATE RESULT: " + createResult.toString()) log.info("getIssue() do CreateResult: " + createResult.getIssue()) linkIssueToEpic(createResult.issue, issue, user, log) if (!createResult.isValid()) { log.error("CREATE RESULT NOT VALID") log.error( createResult.getErrorCollection()) return false; } }else{ log.error("Errors: "+createValidationResult.getErrorCollection().getErrorMessages().size()) log.error("Warnings: "+createValidationResult.getWarningCollection().getWarnings().size()) } return true } static boolean linkIssueToEpic(MutableIssue issue, Issue epicIssue, ApplicationUser user, Logger log) { log.info("A TENTAR LINKAR") def customFieldManager = ComponentAccessor.customFieldManager log.info("CRIOU CUSTOMER MANAGER") def issueManager = ComponentAccessor.issueManager log.info("CRIOU O ISSUE MANAGER") log.info("ISSUE OBJECT: " + issue.getDescription()) def customFieldsObjects = customFieldManager.getCustomFieldObjects(issue) for(cF in customFieldsObjects){ log.info("CUSTOM FIELD VALUE: " + cF.toString()); } def epicLinkField = customFieldManager.getCustomFieldObjects(issue).find { it.name == 'Epic Link' } log.info("A SETTAR CUSTOM FIELD") issue.setCustomFieldValue(epicLinkField, epicIssue) log.info("A FAZER UPDATE DO ISSUE") issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false) return true } }
best regards,
Isabel Fonseca