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:
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 ) } }
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
I'm really sorry, but would you mind formatting your code using code blocks?
It’s a bit hard for us to read and understand it otherwise—after all, we're humans, not machines 🙂
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, thanks. I am not sure but here is a suggestion.
Change your current code section in CreateIssue.groovy
from:
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[]) // <- And here too
}
to
if(type == "Configuration"){
log.info("VERIFICA CFG")
def myAffectedV = issue.affectedVersions.collect { version ->
log.info("affectedVersion: ${version.name} Id: ${version.id}")
version.id.toString()
}
log.info("ITEROU NOS AFFECTED VERSIONS")
issueInputParameters.setAffectedVersionIds(myAffectedV as String[])
}
I wonder if it's related to a type problem, changing long to string may help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Tuncay Senturk _Snapbytes_ ,
Log "
2025-04-08T18:43:27,696 INFO [functions.CreateIssue]: VERIFICA CFG
2025-04-08T18:43:27,699 INFO [functions.CreateIssue]: affectedVersion: 2.0 Id: 29508
2025-04-08T18:43:27,700 INFO [functions.CreateIssue]: ITEROU NOS AFFECTED VERSIONS
2025-04-08T18:43:27,753 ERROR [workflow.AbstractScriptWorkflowFunction]: Workflow script has failed on issue CODE-211095 for user 'i2sifo'. View here: https://jiraserver.i2s.pt/jira-testes/secure/admin/workflows/ViewWorkflowTransition.jspa?workflowMode=live&workflowName=IMPDEV+Epic+Workflow&descriptorTab=postfunctions&workflowTransition=1&highlight=4
groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.IssueInputParametersImpl.setAffectedVersionIds() is applicable for argument types: ([Ljava.lang.String;) values: [[29508]]
Possible solutions: setAffectedVersionIds([Ljava.lang.Long;), getAffectedVersionIds()
at pt.i2s.jira.functions.CreateIssue.createIssue(CreateIssue.groovy:117) ~[?:?]
at pt.i2s.jira.functions.CreateIssue$createIssue.call(Unknown Source) ~[?:?]
at CreateStories.run(CreateStories.groovy:52) ~[?:?]
Start of logs truncated as they exceeded 300 lines."
If you have any further suggestions for resolution, please share.
When I manage to solve it, I'll let you know.
Regards,
Isabel Fonseca
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, another version :)
if(type == "Configuration"){
log.info("VERIFICA CFG")
def affectedVersions = issue.affectedVersions
def versionIds = affectedVersions.collect { version ->
log.info("affectedVersion: ${version.name} Id: ${version.id}")
version.id as Long
}
log.info("ITEROU NOS AFFECTED VERSIONS")
issueInputParameters.setAffectedVersionIds(versionIds as Long[])
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Tuncay Senturk _Snapbytes_ ,
After testing, I see that it doesn't work:
Original print:
Regards
Isabel Fonseca
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Good news, it's resolved.
The situation was caused because I should add the field in the screen scheme of issue type Story (son).
Many thanks,
Best regards,
Isabel Fonseca
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That's good news. I'm glad you resolved the problem.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.